要把 Google Antigravity 提醒傳送到 Telegram、Slack 或 Discord,請在該 App 中建立機器人或傳入 webhook,然後在 ~/.gemini/config/hooks.json 中加入一個 Stop hook,在回合結束時用 curl 發佈一則簡短訊息。Telegram 需要機器人權杖和你的聊天 ID;Slack 和 Discord 只需要 webhook URL。Stop payload 不包含 Antigravity 的最後一則訊息,所以腳本會從對話的記錄檔中讀取。這裡沒有信任步驟:hook 從你下一個 agy 工作階段起就會執行。下面的腳本可在 Mac 和 Linux 上使用,另有一個簡短的 PowerShell 版本適用於 Windows。
01取得權杖或 webhook
Telegram
- 在 Telegram 中傳訊息給 @BotFather,傳送
/newbot並依照步驟操作。它會給你一個像123456:ABC...的機器人權杖。 - 傳送任何一則訊息給你的新機器人。
- 在瀏覽器中開啟
https://api.telegram.org/bot<TOKEN>/getUpdates,找到"chat":{"id":...}。那個數字就是你的聊天 ID。
Slack
- 為你的工作區建立一個 Slack App,開啟 Incoming Webhooks,並為某個頻道加入 webhook。私人頻道或傳給自己的私訊都很適合。
- 複製 webhook URL(
https://hooks.slack.com/services/...)。
Discord
- 在你管理的伺服器中,開啟頻道設定,然後依序選擇 Integrations、Webhooks、New Webhook。
- 複製 webhook URL(
https://discord.com/api/webhooks/...)。
請把這些全都當成密碼對待。任何擁有 URL 或權杖的人都能在你的頻道發佈訊息。
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
}
沒有任何欄位包含最終回覆。它在記錄檔中:最後一行 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 模式不需詢問就執行的那些。有兩件事讓它不適合用來發送聊天提醒:
- 它採用 fail-closed。沒有輸出決定、以錯誤結束或逾時的
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 App。它是獨立工具,與 Google 無關。用手機核准指令說明了它的運作方式。
09常見問題
三者中哪一個設定最快?
Slack 和 Discord:一個 webhook URL 就完成了。Telegram 需要機器人和聊天 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 再次開始工作,那個回合結束時也會有自己的訊息。
可以把提醒傳到團隊頻道嗎?
可以,但請想想訊息會透露什麼。你專案中的檔案路徑、程式碼和錯誤訊息,頻道裡的每個人都會看到。