最近配置 OpenClaw 定时任务时遇到了推送失败的问题,花了些时间排查,这里记录一下解决方案。

问题现象

定时任务执行后状态显示 error,查看日志发现:

Feishu API 400: Invalid ids: [heartbeat]

排查过程

一开始以为是 channel 配置问题,把 channel"last" 改成 "feishu" 后,任务能执行了,但消息还是没收到。

接着又怀疑是时区问题,尝试了 UTC 时间和本地时间的各种写法,依然不行。

最后仔细查看日志,发现了关键错误:

Delivering to Feishu requires target <chatId|user:openId|chat:chatId>

原来飞书渠道必须指定 --to 参数

正确的配置方法

飞书定时任务的完整格式:

openclaw cron create \
  --name "任务名称" \
  --cron "0 8 * * *" \
  --tz "Asia/Shanghai" \
  --channel feishu \
  --to "user:你的OpenID" \
  --best-effort-deliver \
  --message "任务内容"

三个关键点:

  1. --tz "Asia/Shanghai" —— 确保按本地时间执行
  2. --channel feishu —— 指定飞书渠道
  3. --to "user:xxx"--to "chat:xxx" —— 必须指定目标用户或群组 ID

常见命令

# 查看所有任务
openclaw cron list

# 修改任务投递设置
openclaw cron edit <job-id> \
  --announce \
  --channel feishu \
  --to "user:xxx" \
  --best-effort-deliver

# 修改任务时区
openclaw cron edit <job-id> --tz "Asia/Shanghai"

经验总结

  1. 不要想当然--channel feishu 只是第一步,必须配合 --to 使用
  2. 完整测试:创建任务后先用 --at 做个几分钟后的测试,确认能收到消息
  3. 统一时区:建议所有任务都加上 --tz,避免时区混乱

记住:飞书推送,--to 参数不能省。