定时任务
让你的 Agent 按计划执行任务,并把结果发送给你。
你的 Agent 可以按定时器执行任务。例如,它可以每天早上给你发送新闻摘要,或者每小时检查一次某个网站。定时任务运行在 VPS 上,所以你的电脑可以关机。
添加任务
officeclaws cron add \
--name morning-digest \
--schedule "0 9 * * 1-5" \
--timezone Europe/Berlin \
--message "Give me a 5-bullet summary of today's top tech news."| 参数 | 必填 | 含义 |
|---|---|---|
--name | 是 | 任务的简短名称 |
--schedule | 是 | 运行时间,使用 cron 格式 |
--message | 是 | 每次运行时 Agent 要做什么。像写聊天消息一样写即可。 |
--timezone | 否 | 一个 IANA 时区,例如 Europe/Berlin 或 America/New_York。默认是 UTC。 |
--channel | 否 | 结果发送到哪里:chat(默认)或 telegram |
--target | 否 | 用于 telegram:你的 Telegram 用户 ID(见下文) |
把结果发送到 Telegram
先 连接 Telegram。然后把配对步骤中得到的 USER-ID 作为目标:
officeclaws cron add \
--name morning-digest \
--schedule "0 9 * * *" \
--timezone Europe/Berlin \
--message "Weather and top 3 news for today." \
--channel telegram \
--target 123456789查看和删除任务
officeclaws cron listNAME SCHEDULE TZ CHANNEL ENABLED NEXT
morning-digest 0 9 * * 1-5 Europe/Berlin telegram true 2026-10-20T09:00:00+02:00
officeclaws cron rm morning-digest计划格式
计划由五个字段组成:minute hour day-of-month month day-of-week。
| 计划 | 运行时间 |
|---|---|
0 9 * * * | 每天 09:00 |
0 9 * * 1-5 | 工作日 09:00 |
*/30 * * * * | 每 30 分钟 |
0 */4 * * * | 每 4 小时 |
0 18 * * 5 | 每周五 18:00 |
0 8 1 * * | 每月 1 日 08:00 |
每次定时运行都会消耗你的 ChatGPT 额度。非常频繁的任务(例如每分钟一次)会很快把额度用完。