# we-mp-rss Message Task — API Reference

## Full working example (tested 2026-06-03)

### 1. Create message task

```bash
curl -s -X POST "http://localhost:8001/api/v1/wx/message_tasks" \
  -H "Authorization: AK-SK WKn4pIoh3HE_OTwB8tSeIAf5BdgBhJ2aY7:SKuv1aZ_NQtvh7AKo-5WGVc51JOjH345us" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "企微群文章推送",
    "message_type": 0,
    "message_template": "📰 {{ feed.mp_name }} 更新\n{% for article in articles %}\n> **{{ article.title }}**\n> 🔗 {{ article.url }}\n{% endfor %}",
    "web_hook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d4de64e1-efaa-4f03-a833-ad85c1d6de5b",
    "mps_id": "[{\"id\": \"MP_WXS_3886864470\"}, {\"id\": \"MP_WXS_3596295911\"}]",
    "cron_exp": "*/30 * * * *",
    "status": 1
  }'
```

### 2. Reload scheduler

```bash
curl -s -X PUT "http://localhost:8001/api/v1/wx/message_tasks/job/fresh" \
  -H "Authorization: AK-SK WKn4pIoh3HE_OTwB8tSeIAf5BdgBhJ2aY7:SKuv1aZ_NQtvh7AKo-5WGVc51JOjH345us"
```

### 3. Manually trigger a test run

```bash
curl -s "http://localhost:8001/api/v1/wx/message_tasks/<TASK_ID>/run?isTest=true" \
  -H "Authorization: AK-SK ..."
```

### 4. Manually trigger a real run

```bash
curl -s "http://localhost:8001/api/v1/wx/message_tasks/<TASK_ID>/run?isTest=false" \
  -H "Authorization: AK-SK ..."
```

## Error log

### 405 Method Not Allowed on POST to /api/v1/message_tasks

Root cause: API_BASE = "/api/v1/wx" (defined in `core/base.py`). Correct path is `/api/v1/wx/message_tasks`.

### "string indices must be integers, not 'str'" on /run

Root cause: `mps_id` was `["MP_WXS_xxx"]` (array of strings), but `get_feeds()` does `item["id"]` expecting objects. Fix: use `[{"id": "MP_WXS_xxx"}]`.

### No articles pushed after task creation

Root cause: Message tasks only push articles fetched *during this run* (via `UpdateArticle` callback). Previously-fetched articles are skipped. Workaround: push existing articles directly via webhook URL.

## Template variable reference

The template data context in `send_message()` (webhook.py):

```python
data = {
    "feed": hook.feed,        # Feed object
    "articles": hook.articles, # List of Article dicts
    "task": hook.task,         # MessageTask object
    "now": "2026-06-03 16:00"  # str
}
```

Common variables:
- `{{ feed.mp_name }}` — 公众号名称
- `{{ article.title }}` — 文章标题
- `{{ article.url }}` — 文章链接
- `{{ article.publish_time }}` — 发布时间
- `{{ article.description }}` — 文章描述
- `{{ now }}` — 当前时间
