name: wechat-get-messages
从后端拉取微信消息列表。支持三种常见用法:
wxid=wxid_abc123 只看某人的对话since=<ISO时间戳> 只拿该时间之后的新消息(轮询场景)Step 1:根据用户意图组装 query string。可选参数:
| 参数 | 说明 | 示例 |
|---|---|---|
limit |
返回条数,默认 50,最大 200 | limit=20 |
wxid |
只看某联系人 | wxid=wxid_abc123 |
direction |
sent=自己发的,received=别人发的 |
direction=received |
since |
ISO 时间戳,增量拉取 | since=2026-04-17T10:00:00.000Z |
Step 2:用 exec/bash 工具执行(示例:拉最近 20 条别人发来的):
API_BASE=$(node -e "console.log(JSON.parse(require('fs').readFileSync(require('path').join(require('os').homedir(),'.openclaw','wechat-credentials.json'),'utf8')).wechatApiBase)")
curl -s --max-time 15 -G "$API_BASE/messages" \
--data-urlencode "limit=20" \
--data-urlencode "direction=received"
增量拉取示例:
curl -s -G "$API_BASE/messages" --data-urlencode "since=2026-04-17T10:00:00.000Z"
Step 3:解析响应。每条消息关键字段:
fromWxid — 发送者 wxid(回复目标)toWxid — 接收者 wxidnickName — 发送者昵称type — text/image/voice/link/emoji/system 等content — 文字内容或媒体摘要timestamp — ISO 时间戳(用作下次 since)Step 4:根据业务做下游处理:
type=text 且 direction=received → 调 wechat-send-text(fromWxid, 回复)fromWxid 形如 xxx@chatroom,个人形如 wxid_xxxweixin/fmessage/gh_*(系统和公众号)timestamp,下次作为 since 传入