跳到主要内容

把定时挪出 Grok Bot:有活时才用 webhook 叫醒 routine

XXPasdawan2026-11-26

编程与仓库踩坑与局限作者自述未复现建议先读

概要

跑着约 29 个 Grok Bot agent 的作者,把经常空跑的定时 routine 换成常开 Mac 等电脑上的廉价脚本,只在有活时向 webhook 触发的 routine 发 POST,并让 Grok Bot 把重编程活交给 Claude Code 或 Codex CLI;共 7 步,附可复制提示词、脚本和定时示例。

核心流程

起因:定时 routine 即使无事可做也在烧用量。作者在 Grok Bot 上跑大约 29 个 agent,见过刚上手时的热情(每小时查邮件、盯文件夹、看队列)在一周结束前就把用量条清空。定时 routine 就是一段保存的提示词加一个触发器;每次触发都会重新跑一遍,读指令、判断有没有事要做,哪怕只回一句「没事」也是一次模型回合,要计入用量,在 Settings 的 Usage & Billing 里能看到。作者引用 xAI 文档:每小时一次的计划、很短的间隔或盯着繁忙频道的 Slack 触发器,一天就能用掉一周的量。办法是把时钟挪到 Grok Bot 外面:让一台常开的普通电脑(Mac、MacBook Air;VPS 可选)做廉价检查,只有真有活时才调用 routine 的 webhook。本身就该定时的,比如早间摘要,保持不变。需要准备:一个 Grok Bot agent、一台常开的电脑、一个不用启动 Grok Bot 就能检查的条件(文件、文件夹、日期、计数)。

  1. 自己做:找出经常空跑的 routine(第 1 步)。点聊天顶部的 agent 名字或按 Cmd+Shift+I 打开 agent 信息面板,查看 Routines 列表。逐个看定时 routine 有多少次只是为了报告「没事发生」,先挪这些。抓住一个反复空跑的检查就足以掌握这个模式。
  2. 交给 bot:建一个 webhook 触发的 routine(第 2 步)。作者不编菜单名,直接在聊天里让 Grok Bot 建。保存的提示词写清被唤醒后做什么、结果给谁,没东西可报就一句话结束,并且不加定时。作者的提示词:

    中文意思:建一个名为 Wake when the checker finds work 的 webhook 触发 routine;触发时把 webhook 事件当作唤醒原因,事件写清就去做,不清楚就说缺什么,然后在聊天里汇报;没事做就一句话结束;不要加定时;保存后告诉我去哪里复制 webhook URL、key 和 Authorization 头,并提醒我不要把 key 贴回聊天。

    Create a webhook-triggered routine named "Wake when the checker finds work". When it fires, treat the webhook event as the reason you woke. Do the job described in the event if it is clear. If it is not, say what is missing. Then report the result to me in this chat. If there is nothing to do after all, say so in one line and stop. Do not put a schedule on this routine. I only want it to run when something POSTs to its webhook URL. When it is saved, tell me where to copy the webhook URL, the webhook key and the Authorization header, and remind me not to paste the key back into this chat.

  3. 自己做:复制 webhook URL 和 key 并妥善保管(第 3 步)。在 agent 信息面板里打开 Routines,再打开触发方式为 When a webhook fires 的 routine,面板上有 Webhook URL、Webhook key 和 Authorization header 三项。请求头是 Authorization: Bearer YOUR_SECRET,其中密钥就是 webhook key。把 key 当密码对待:URL 和 key 放在调用方机器上一个只有自己能读的 .env 文件里(chmod 600 即可),由脚本加载,绝不写进 crontab、聊天、提示词或 git 仓库。
  4. 交给 bot:让 Grok Bot 写一个小检查脚本(第 4 步)。脚本只做一次廉价检查,没事就安静退出,有活才向 webhook 发 POST,带 JSON 正文(任意 JSON,Grok Bot 会把它作为数据交给 routine)和 Content-Type: application/json 请求头;它从不为判断有没有活而启动 Grok Bot。想更严格,可以用 HMAC-SHA256 给 JSON 正文签名,再在 routine 里验证。作者让 agent 写文件的提示词:

    中文意思:写一个叫 check-and-wake.sh 的小 bash 脚本:从只有本人能读的 .env 加载 URL 和密钥,缺了就报错退出、绝不打印密钥、绝不从 crontab 读;做一次可替换的廉价检查,不调用任何模型;没事就安静退出 0;有活就用 curl 按指定请求头和 JSON 正文 POST;POST 失败返回非零。另给一条工作日 9:00 的 crontab 和一个 launchd plist,用占位路径,crontab 里不得有 URL 和密钥;不写死任何真实主机名、URL 或密钥。

    Write a small bash script called check-and-wake.sh that:

    1. Loads YOUR_WEBHOOK_URL and YOUR_SECRET from a .env file that only the owner can read. If either is missing, exit with an error. Never print the secret. Never read these values from a crontab line.
    2. Runs one cheap check. Start with a placeholder I can replace, for example "does this file exist" or "is this folder non-empty." The check must not call Grok Bot or any other model.
    3. If the check finds nothing to do, exit 0 with no output.
    4. If it finds work, POST to YOUR_WEBHOOK_URL with curl, using these exact headers and a JSON body:

    Authorization: Bearer YOUR_SECRET Content-Type: application/json -d '{"source":"cron","message":"task due"}' The body can be changed later; it is required, and Grok Bot passes it to the routine as data.

    1. Exit non-zero if the POST fails.

    Also give me a one-line crontab entry for weekdays at 9:00, and a launchd plist that runs the same script at 9:00 on weekdays, using placeholder paths. The crontab must not contain the URL or the secret. Do not hard-code any real hostnames, URLs or secrets.

    文中还给了一个只含占位符的脚本样例:加载 $HOME/.env,$HOME/incoming/ready.flag 为空或不存在时退出 0,否则用 curl 发 POST。

  5. 自己做:给检查脚本排时间,而不是给 Grok Bot routine 排(第 5 步)。跑脚本的机器必须常开。Mac 上用 cron 或 launchd;文中的 launchd plist 有五个日历条目,对应周一到周五 9:00(launchd 把 0 当作周日),标签和路径自行替换,plist 里不放 webhook key。用 VPS 的话,一行 crontab 就能在本地时间工作日 9:00 运行:

    中文意思:工作日 9:00 运行检查脚本的 crontab 行。

    0 9 * * 1-5 /home/YOU/bin/check-and-wake.sh

  6. 自己做:删任何东西之前先测三种情况(第 6 步)。安静运行:没活时脚本退出 0,agent 保持休眠,用量不动。有活运行:POST 成功、routine 运行;返回 200 只表示 Grok Bot 接受了调用并开始运行,跑完的 routine 通常会显示一条 Automation completed 摘要,或按提示词把结果带回聊天。重复触发:同一件活连发两次 webhook,应该只出一份工作;如果启动了第二份,就改保存的提示词,让 bot 能识别已在进行的工作。安静运行却唤醒了 bot,说明脚本不该发却发了;有活却没动静,就查是否返回 200、是否带了 Bearer 请求头和 JSON 正文、routine 是否被暂停。
  7. 自己做:删掉旧的定时 routine(第 7 步)。三项测试都通过后,再让 Grok Bot 删除旧的定时 routine,或取消它的定时;两者都留着,就等于既为空跑付费又多了 webhook。想要保底,可以设一个频率低得多的定时 routine,或在检查脚本上加日志,免得漏响的门铃看起来像平静的一天。

自己做:所有 agent 用同一套规则。把通用规则放在第二大脑里的一个地方,每个 agent 启动时都读,包括被 webhook 唤醒之后;角色专属指令叠加在上面,每次改规则都要注明日期、可回退,并由用户批准。作者的提示词:

中文意思:帮我建一个所有 Grok Bot agent 启动时都会读的共享规则处:一套通用规则、每个角色一段补充、一份由我批准的带日期且可回退的修改记录;为由 routine webhook 唤醒的 agent 起草通用规则:未经我明确同意不发布、不花钱,做完写回改了什么;保持通用,不编路径或文件名,并给一份让每个 agent 指向同一来源的清单。

Help me set up a single place for shared rules that every Grok Bot agent will read at startup, including when a webhook-triggered routine wakes it. I want:

  • one common set of rules any of my Grok Bot agents can load
  • a short add-on for each role, on top of the common rules
  • a dated, reversible record of rule changes, which I approve

Draft the common rules for a setup where Grok Bot agents are woken by a routine webhook, they must not publish or spend money without my explicit OK, and they should write back what changed when they finish a job. Keep it generic. Do not invent folder paths or product-specific filenames. Give me a short checklist for pointing each Grok Bot agent at that same source.

交给 bot:让 Grok Bot 当调度,把特殊活交给 Claude 或 Codex。普通活 bot 自己干;遇到编程任务或大块工作,就在已注册的电脑或它自己的电脑上启动已登录对应订阅的 Claude Code CLI 或 Codex CLI,等待、读取结果再继续,这样重活跑在那份订阅上,而不是一次很长的 Grok Bot 回合。作者说明这是原理,不是已核实的内置按钮或命令。作者的提示词:

中文意思:帮我给这个 agent 设一条分派规则:Grok Bot 保持调度,普通活自己做;编程、大块或更适合 Claude/Codex 的活,不要长时间自己跑,而是一句话说明交给谁,在已登录订阅的电脑上运行对应 CLI,等结束、读结果、在聊天里继续;CLI 缺失、未登录或失败就一句话说明并停下,不编结果;不写死真实路径、主机名或账号,给我一份机器准备清单和规则草稿,保存前先让我批准。

Help me set up a routing rule for this Grok Bot agent. I want Grok Bot to stay the orchestrator. When I ask for ordinary work, do it yourself. When the job is a coding task, a large piece of work, or another special case that Claude or Codex would handle better, do not try to do the whole job as a long Grok Bot run. Instead:

  • decide whether the job should go to Claude or to Codex, and tell me why in one line
  • run the Claude Code CLI or the Codex CLI on my registered computer or on your computer, using the subscription already signed in there
  • wait for that run to finish, read the result, and continue the work in this chat
  • if the CLI is missing, not signed in, or fails, say so in one line and stop. Do not invent a result.

Do not hard-code real folder paths, hostnames, or account names. Give me a short checklist of what I need on the machine (the CLI installed, the subscription signed in, and a computer Grok Bot can use), and a draft of the standing rule this agent should follow. Ask me to approve the rule before you save it.

怎么检查:原文没写作者怎么核实省下的用量;第 6 步是作者给出的测试方法,下面的费用对比是作者自己的估算。

核心观点和结果

  • routine 不变,没活时 Grok Bot token 消耗为零。检查脚本安静运行时不会唤醒 agent,只有向 routine webhook 发 POST 才会。这是作者的说法,原文没有对比数字。
  • 作者的费用估算,不是实际账单:Grok Bot $30 加 Claude 或 Codex $20 就能做很多事,同样的活只靠 Grok Bot 可能要 $100 或 $200 档。作者注明 $30 是包含 Grok Bot 的最便宜 xAI 套餐(https://x.ai/pricing),Claude Pro 每月 $20,Codex 包含在每月 $20 的 ChatGPT Plus 里。
  • 作者不编造界面。没有可靠点击路径的地方(打开本地执行、技能页面、发送给 Claude 的控件),文中都直说,并建议去问 Grok Bot。
  • 从来不响的门铃看起来就像平静的一天。预期有活却没动静,要查检查脚本有没有跑、查到了什么、POST 有没有发出。
  • 重要决定留给人。agent 起草;任何发布和花钱的事由用户批准。收尾建议:本周先拿一个空跑的 routine 试试。

来源

平台
X
原作者
Pasdawan
原文日期
分类
编程与仓库、踩坑与局限

这条证据标签是什么意思

作者自述未复现

做法和结果来自作者自己的描述,本站没有独立复现。

阅读编辑与证据规范

同场景的其他案例

非官方社区项目,与 xAI 没有隶属关系,也未获 xAI 认可或背书。没有注册。做法和数字属于原作者。