要把 Google Antigravity 提醒发送到 Telegram、Slack 或 Discord,请先在对应应用中创建一个机器人或传入 webhook,然后在 ~/.gemini/config/hooks.json 中添加一个 Stop hook,在一轮结束时用 curl 发送一条简短消息。Telegram 需要机器人 token 和你的 chat ID;Slack 和 Discord 只需要一个 webhook URL。Stop payload 不包含 Antigravity 的最后一条消息,所以脚本会从对话的 transcript 文件中读取。没有信任步骤:hook 从你的下一个 agy 会话起就会运行。下面的脚本适用于 Mac 和 Linux,Windows 则有一个简短的 PowerShell 版本。
01获取 token 或 webhook
Telegram
- 在 Telegram 中给 @BotFather 发消息,发送
/newbot并按步骤操作。它会给你一个类似123456:ABC...的机器人 token。 - 给你的新机器人发送任意一条消息。
- 在浏览器中打开
https://api.telegram.org/bot<TOKEN>/getUpdates,找到"chat":{"id":...}。这个数字就是你的 chat ID。
Slack
- 为你的工作区创建一个 Slack 应用,开启 Incoming Webhooks,并为某个频道添加 webhook。私有频道或发给自己的私信都很合适。
- 复制 webhook URL(
https://hooks.slack.com/services/...)。
Discord
- 在你管理的服务器中,打开频道设置,然后依次进入 Integrations、Webhooks、New Webhook。
- 复制 webhook URL(
https://discord.com/api/webhooks/...)。
请像对待密码一样对待这些信息。任何拿到 URL 或 token 的人都能向你的频道发消息。
02Stop hook 收到什么
Antigravity 会通过 stdin 向每个 hook 发送一个 JSON 对象,键名采用 camelCase。Stop 的内容如下(已精简):
{
"hookEventName": "Stop",
"cwd": "/Users/you/projects/demo",
"conversationId": "32fc0aec-…",
"transcriptPath": "/Users/you/.gemini/antigravity-cli/brain/32fc0aec-…/.system_generated/logs/transcript_full.jsonl",
"lastUserInput": "Run the tests and fix what fails",
"terminationReason": "NO_TOOL_CALL",
"executionNum": 0,
"fullyIdle": true
}
其中没有包含最终回复的字段。它在 transcript 中:最后一行 type 为 PLANNER_RESPONSE 且带有 content 的记录。
03一个脚本搞定三种服务
保存为 ~/.gemini/agy-chat-notify.sh,填写你使用的服务,然后对它运行 chmod +x:
#!/bin/sh
# Posts "Antigravity has finished" to Telegram, Slack or Discord.
SERVICE="slack" # telegram | slack | discord
TELEGRAM_TOKEN="" TELEGRAM_CHAT="" # for telegram
WEBHOOK_URL="" # for slack or discord
text=$(python3 -c '
import json, os, sys
try:
e = json.load(sys.stdin)
except Exception:
sys.exit(0)
if e.get("hookEventName") != "Stop":
sys.exit(0)
project = os.path.basename(e.get("cwd", "")) or "Antigravity"
msg = ""
try:
with open(e.get("transcriptPath", "")) as f:
for line in f:
try:
step = json.loads(line)
except ValueError:
continue
if step.get("type") == "PLANNER_RESPONSE" and (step.get("content") or "").strip():
msg = step["content"].strip()
except OSError:
pass
msg = (msg or "Turn complete")[:300]
print(f"Antigravity finished in {project}: {msg}")
')
if [ -n "$text" ]; then
json=$(printf '%s' "$text" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')
case "$SERVICE" in
telegram) curl -s -o /dev/null --max-time 10 \
--data-urlencode "chat_id=$TELEGRAM_CHAT" --data-urlencode "text=$text" \
"https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" ;;
slack) curl -s -o /dev/null --max-time 10 -H 'Content-Type: application/json' \
-d "{\"text\": $json}" "$WEBHOOK_URL" ;;
discord) curl -s -o /dev/null --max-time 10 -H 'Content-Type: application/json' \
-d "{\"content\": $json}" "$WEBHOOK_URL" ;;
esac
fi
echo '{}'
exit 0
结尾的 echo '{}' 告诉 Antigravity 这个 hook 没什么要说的,于是这一轮正常结束。不要输出其他任何内容:回答 {"decision":"continue","reason":...} 的 Stop hook 会开始新的一轮。
04把它添加到 hooks.json
~/.gemini/config/hooks.json 的顶层键是命名的组,每个组都会运行。为这个脚本添加一个组,使用它的完整路径:
{
"chat-notify": {
"Stop": [
{ "type": "command", "command": "/Users/you/.gemini/agy-chat-notify.sh", "timeout": 20 }
]
}
}
如果文件中已有其他组(例如由其他工具写入的组),请把 "chat-notify" 添加在它们旁边,而不是替换整个文件,并确认它仍是有效的 JSON。然后启动一个新的 agy 会话。如果只想在某个项目中使用这个 hook,请把同样的组放到该项目的 .agents/hooks.json 中。
05Windows
同样的思路用 PowerShell 实现,这里以 Slack 为例(Discord 请用 @{ content = $text })。我们没有在 Windows 上测试过 agy,所以在依赖它之前请确认 hook 会触发。保存为 %USERPROFILE%\.gemini\agy-chat-notify.ps1:
$webhook = "https://hooks.slack.com/services/..."
$e = [Console]::In.ReadToEnd() | ConvertFrom-Json
if ($e.hookEventName -eq "Stop") {
$project = Split-Path -Leaf $e.cwd
$msg = "Turn complete"
if (Test-Path $e.transcriptPath) {
foreach ($line in Get-Content $e.transcriptPath) {
try { $step = $line | ConvertFrom-Json } catch { continue }
if ($step.type -eq "PLANNER_RESPONSE" -and $step.content) { $msg = $step.content.Trim() }
}
}
if ($msg.Length -gt 300) { $msg = $msg.Substring(0, 300) }
$body = @{ text = "Antigravity finished in ${project}: $msg" } | ConvertTo-Json
try { Invoke-RestMethod -Method Post -Uri $webhook -ContentType 'application/json' -Body $body -TimeoutSec 10 | Out-Null } catch {}
}
Write-Output '{}'
在组中使用 "command": "powershell -NoProfile -ExecutionPolicy Bypass -File C:\\Users\\you\\.gemini\\agy-chat-notify.ps1"。
06“Antigravity 想要运行命令”怎么办?
Antigravity 没有通知或权限事件。hook 唯一能看到命令的地方是 PreToolUse,它在每次工具调用前触发,包括 Auto 模式下无需询问就运行的调用。有两点让它不适合用来发聊天提醒:
- 它采用失败即拒绝。一个没有输出决定、出错退出或超时的
PreToolUsehook 会阻止该工具。放在那里的聊天提醒每次都必须输出{"decision":"allow"},即使发送失败也一样。 - 它无法判断 Antigravity 是否会询问。你会为每条命令都收到一条消息,而不只是那些在等你的命令。
如果你仍然想要,请筛选 toolCall.name 为 run_command 的调用,发送 toolCall.args.CommandLine,让 curl --max-time 保持简短,并且始终以 {"decision":"allow"} 结尾。PreToolUse 指南解释了各种决定。
07注意你发送的内容
消息中包含项目名称和 Antigravity 的最后一条回复,其中可能引用代码、路径或错误信息。在共享的 Slack 或 Discord 频道中,所有人都能看到。请使用私有频道或私信,如果你的工作比较敏感,就把消息精简一些。
08只能单向
聊天消息会告诉你 Antigravity 完成了,但无法把你的回答传回会话。要做到这一点,Google 的 Remote Control 可以在手机浏览器中使用,而 Antigravity Notifier 是 agy 命令行的双向方案:适用于 Mac、Windows 和 Linux 的免费 antigravity-notifier 工具,加上 iPhone 或 Android 应用,你可以在应用中批准或拒绝命令、回答问题并发送下一条指令。它是独立产品,与 Google 无关联。在手机上批准命令介绍了它的工作原理。
09常见问题
三者中哪个设置最快?
Slack 和 Discord:一个 webhook URL 就搞定了。Telegram 需要机器人和 chat ID,但它的手机通知很可靠。
为什么什么都收不到?
先启动一个新的 agy 会话,因为 hook 在会话启动时加载。然后用一个模拟事件手动运行脚本:echo '{"hookEventName":"Stop","cwd":"/tmp/demo"}' | ~/.gemini/agy-chat-notify.sh。它应该输出 {} 并发送“Turn complete”。测试时从 curl 这一行中去掉 -s -o /dev/null,以便看到服务的回复,并检查 hooks.json 是有效的 JSON。
每一轮之后都会收到消息吗?
是的,每个 Stop 一条。如果你发送了后续指令,Antigravity 又开始工作,那一轮结束时也会单独发一条消息。
可以把提醒发到团队频道吗?
可以,但要想想消息会暴露什么。你项目中的文件路径、代码和错误信息会被频道里的所有人看到。