SKILL.md 2.0 KB


name: wechat-send-text

description: 向指定微信好友或群聊发送文字消息。这是自动应答的核心技能,用户说"发微信给某某"时用这个。

wechat-send-text

向指定 wxid(好友或群聊)发送一条文字消息。这是 WeChat 技能中最常用的一个。

触发场景

  • 用户说:"帮我发微信给 wxid_xxx,说内容 yyy"
  • 用户说:"回复 某某 这段话"
  • 自动应答流程里收到新消息后需要回复

执行步骤(LLM 请按顺序执行)

Step 1:(推荐)先调用 wechat-check-online 技能确认账号在线。

Step 2:从用户请求里提取两个参数:

  • toWxid:接收方 wxid(好友形如 wxid_abc123;群聊形如 12345@chatroom
  • content:要发送的文字内容

如果用户没给出明确的 wxid,先问清楚。不要猜

Step 3:用 exec/bash 工具执行:

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 -X POST "$API_BASE/message/send-text" \
  -H "Content-Type: application/json" \
  -d '{"toWxid":"<替换为真实wxid>","content":"<替换为真实内容>","ats":""}'

注意:<替换为...> 要真的替换为实际值。JSON 里的双引号和特殊字符需要转义;如果 content 含特殊字符,用 bash 的 heredoc 或 jq -n 构造 payload。

群聊中 @ 某人时,ats 字段传被 @ 的 wxid(多个用英文逗号)。

Step 4:解析响应。后端返回:

{ "ret": 200, "msg": "发送成功" }
  • ret == 200 → 回复用户:"已发送。"
  • 否则 → 把 msg 报给用户

重要提示

  • 不要wechat-send-text 当成 shell 命令 exec
  • 不要虚构什么"channels"概念——直接走上面的 curl 就能发
  • 发送前建议 check-online,但不强制(掉线时 curl 会拿到明确错误)