Install
openclaw skills install weixin-cron-push通过 OpenClaw Cron 定时任务向微信用户主动推送消息(天气、提醒、新闻摘要等)。当用户需要:设置定时提醒、每日推送、定时通知、微信主动发消息、cron 推送到微信时触发。支持一次性(at)和循环(cron/every)任务,通过 sessionKey 路由到指定微信用户,AI 对话模式下自动获取 sessionKey。
openclaw skills install weixin-cron-push通过 Cron 定时任务实现微信主动推送。
Cron agentTurn → 独立会话 → --announce + --channel openclaw-weixin → 微信投递到用户手机
关键:
--session-key 指定用户的微信会话桶(格式:agent:main:openclaw-weixin:direct:<userId>@im.wechat)--announce --channel openclaw-weixin 确保回复通过微信投递--message(agentTurn)而非 --system-event(systemEvent 走 main 桶,无法投递)openclaw-weixin 已安装启用openclaw cron add \
--name "提醒标题" \
--at "2026-04-29T10:00:00Z" \
--message "请告诉用户:这是提醒内容" \
--session-key "agent:main:openclaw-weixin:direct:<userId>@im.wechat" \
--announce \
--channel openclaw-weixin \
--delete-after-run
openclaw cron add \
--name "每日天气" \
--cron "0 8 * * *" \
--tz "Asia/Shanghai" \
--message "请查询今天天气并发送给用户。" \
--session-key "agent:main:openclaw-weixin:direct:<userId>@im.wechat" \
--announce \
--channel openclaw-weixin
openclaw cron add \
--name "每小时间隔" \
--every "1h" \
--message "请执行 XXX 检查并告知用户结果。" \
--session-key "agent:main:openclaw-weixin:direct:<userId>@im.wechat" \
--announce \
--channel openclaw-weixin
用户直接说"明天早上8点提醒我开会",AI 自动创建任务。AI 需从当前会话获取 sessionKey 并使用上述参数。
# 方法1:从会话列表查找(找含 openclaw-weixin 的 key)
openclaw sessions --json --all-agents | grep openclaw-weixin
# 方法2:从会话文件查找(自动适配 macOS / Linux)
python3 -c "
import json, pathlib
sessions_file = pathlib.Path.home() / '.openclaw' / 'agents' / 'main' / 'sessions' / 'sessions.json'
with open(sessions_file) as f:
for k in json.load(f):
if 'openclaw-weixin' in k and 'direct' in k:
print(k)
"
# 方法3:从微信账号配置获取 userId,拼接为:
# agent:main:openclaw-weixin:direct:<userId>@im.wechat
# userId 在 ~/.openclaw/openclaw-weixin/accounts/*.json 中
| 参数 | 必填 | 说明 |
|---|---|---|
--message <文本> | ✅ | agentTurn 消息内容,AI 处理后回复用户 |
--session-key <key> | ✅ | 微信会话桶 key(决定路由到哪个用户) |
--announce | ✅ | 启用投递(否则回复不发送) |
--channel openclaw-weixin | ✅ | 指定通过微信渠道投递 |
--at <ISO时间> | 调度 | 一次性触发 |
--cron <表达式> | 调度 | Cron 表达式循环 |
--every <间隔> | 调度 | 固定间隔循环(如 10m, 1h) |
--tz <时区> | 否 | 时区(如 Asia/Shanghai) |
--delete-after-run | 否 | 触发后自动删除 |
--name <名称> | 否 | 任务名称 |
--account <id> | 否 | 多账号时指定微信账号 |
| 方式 | 投递 | 说明 |
|---|---|---|
--system-event + --session main | ❌ 不可靠 | 注入 main 桶,没有 deliveryContext,回复无法投递 |
--message + --session-key + --announce | ✅ 可靠 | 独立会话 + 明确投递渠道,消息必定到达微信 |
必须用 --message 方式,不要用 --system-event。
openclaw cron list # 查看活跃任务
openclaw cron list --all # 含已禁用/残留任务
openclaw cron delete <ID> # 删除任务
openclaw cron run <ID> # 立即触发
每个微信用户有独立 sessionKey:
openclaw channels login --channel openclaw-weixin多账号时用 --account 指定微信账号:
openclaw cron add \
--name "每日天气" \
--cron "0 8 * * *" \
--tz "Asia/Shanghai" \
--message "请查询今天天气并发送给用户。" \
--session-key "agent:main:openclaw-weixin:direct:<userId>@im.wechat" \
--announce \
--channel openclaw-weixin \
--account <account-id>
多账号隔离建议:
openclaw config set session.dmScope per-account-channel-peer
userId 正确