# we-mp-rss API Reference & Pitfalls

Project running at `http://localhost:8001` via `rss.icoach.chat`.

## API Base Path

**Actual**: `/api/v1/wx/` (defined in `core/base.py` as `API_BASE`)
**Not**: `/api/v1/`

All endpoints use auth unless noted.

## Authentication

AK/SK format in Authorization header:
```
Authorization: AK-SK <ak_value>:<sk_value>
```

Credentials in project `.env`: `WE_MP_RSS_AK` / `WE_MP_RSS_SK`

## Key Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/v1/wx/message_tasks` | GET | List message tasks |
| `/api/v1/wx/message_tasks` | POST | Create message task |
| `/api/v1/wx/message_tasks/{id}` | PUT | Update message task |
| `/api/v1/wx/message_tasks/{id}/run` | GET | Run task (isTest=true/false) |
| `/api/v1/wx/message_tasks/job/fresh` | PUT | Reload scheduler |
| `/api/v1/wx/mps` | GET | List subscribed feeds |

## Message Task Pitfalls

### mps_id Format (CRITICAL)
Must be JSON array of **objects** with `id` key:
```json
[{"id": "MP_WXS_3886864470"}, {"id": "MP_WXS_3596295911"}]
```
Error if using string array: `string indices must be integers, not 'str'`

### Template Syntax
Uses double-brace `{{ variable }}` (Jinja2-style via `TemplateParser`):
```
📰 {{ feed.mp_name }} 更新
{% for article in articles %}
> **{{ article.title }}**
{% endfor %}
```
NOT single-brace `{variable}`.

### Message Type
- `0` = send message (via `notice()` → `send_wechat_message()`)
- `1` = raw webhook POST

### Runtime Behavior
Message tasks only push **newly fetched** articles. If articles were already fetched
by a previous cron run, the task thinks there are "no new articles" and skips.

### cron_exp Format
Standard 5-field cron. Example: `*/30 * * * *` (every 30 min).

## we-mp-rss Startup

```bash
cd /home/agentuser/project/we-mp-rss-main源文件/we-mp-rss-main
source venv/bin/activate
DB="sqlite:////home/agentuser/project/we-mp-rss-data/db.db" \
ENABLE_JOB=True PORT=8001 BROWSER_TYPE=chromium \
python main.py -job True
```

## Database

SQLite at `/home/agentuser/project/we-mp-rss-data/db.db`
Key tables: `articles`, `feeds`, `message_tasks`, `users`
Admin user: `admin` (password bcrypt-hashed)
