如何在 Google Chat 整合 OpenClaw (Chat API)
想要在工作常用的 Google Chat 裡放個 AI 助手,但每次想到要處理那些複雜的 Google Cloud 設定就頭大?不管是權限設定、Service Account 還是 Webhook 跳轉,光是看文件就讓人想放棄。其實只要抓對重點,這件事沒那麼難。
這篇指南會帶你快速跑通 Google Chat API 的串接流程,讓你的 OpenClaw 助手能直接在私訊或空間裡回覆訊息。
需要準備的東西
Section titled “需要準備的東西”- 一個 Google Cloud 專案
- 已啟用的 Google Chat API
- 一個 Service Account 及其 JSON Key
- 已安裝並運行的 OpenClaw Gateway
1. 準備 Google Cloud 憑證
Section titled “1. 準備 Google Cloud 憑證”首先,去 Google Chat API Credentials 確定 API 已經啟用。
- 點擊 Create Credentials > Service Account。
- 隨便取個名字(例如
openclaw-chat),權限跟存取設定都可以直接跳過按 Done。 - 在列表點進剛建立的帳號,切換到 Keys 標籤,點 Add Key > Create new key。
- 選擇 JSON 並下載。把檔案存到 Gateway 主機上(例如
~/.openclaw/googlechat-service-account.json)。
2. 設定 Google Chat App
Section titled “2. 設定 Google Chat App”到 Google Cloud Console Chat Configuration 設定:
- 填寫 Application info(App 名稱、Avatar URL、描述)。
- 啟用 Interactive features。
- Functionality: 勾選 Join spaces and group conversations。
- Connection settings: 選擇 HTTP endpoint URL。
- Triggers: 選擇 Use a common HTTP endpoint URL for all triggers,網址填你的 Gateway 公開 URL 加上
/googlechat。- 提示:跑
openclaw status可以找到你的公開 URL。
- 提示:跑
- Visibility: 勾選 Make this Chat app available to specific people and groups,並填入你的 Email。
- 點擊 Save。重新整理頁面,找到 App status 改成 Live - available to users 並再次儲存。
3. 配置 OpenClaw
Section titled “3. 配置 OpenClaw”在你的環境變數或設定檔中加入 Service Account 路徑:
- 環境變數:
GOOGLE_CHAT_SERVICE_ACCOUNT_FILE=/path/to/service-account.json - 或設定檔:
channels.googlechat.serviceAccountFile: "/path/to/service-account.json"
啟動 Gateway 後,Google Chat 就會開始把訊息 POST 到你的 Webhook 路徑。
把機器人加入對話
Section titled “把機器人加入對話”- 打開 Google Chat。
- 點擊 Direct Messages 旁邊的 + 號。
- 在搜尋框輸入你剛設定的 App 名稱。
- 注意:因為這是私人 App,它不會出現在 Marketplace 列表,你必須手動搜尋名稱。
- 選擇你的機器人並點擊 Add 或 Chat。
- 傳個「Hello」試試看!
安全性與公開 URL
Section titled “安全性與公開 URL”Google Chat 要求 Webhook 必須是公開的 HTTPS 端點。為了安全,你應該只暴露 /googlechat 這個路徑。
推薦方案:Tailscale Funnel
Section titled “推薦方案:Tailscale Funnel”如果你想保護私有的 Dashboard,只公開 Webhook 路徑,Tailscale Funnel 是最好的選擇。
-
檢查 Gateway 綁定的位址:
Terminal window ss -tlnp | grep 18789 -
只對內網公開 Dashboard (Port 8443):
Terminal window tailscale serve --bg --https 8443 http://127.0.0.1:18789 -
公開 Webhook 路徑:
Terminal window tailscale funnel --bg --set-path /googlechat http://127.0.0.1:18789/googlechat
這樣你的 Webhook 網址就是 https://<node-name>.<tailnet>.ts.net/googlechat,而 Dashboard 依然留在私有的 8443 Port。
替代方案:Caddy
Section titled “替代方案:Caddy”如果你習慣用 Caddy,可以這樣設定:
your-domain.com { reverse_proxy /googlechat* localhost:18789}Config highlights
Section titled “Config highlights”這是一個典型的配置範例:
{ channels: { googlechat: { enabled: true, serviceAccountFile: "/path/to/service-account.json", audienceType: "app-url", audience: "https://gateway.example.com/googlechat", webhookPath: "/googlechat", botUser: "users/1234567890", // 選填,幫助偵測 @mention dm: { policy: "pairing", allowFrom: ["users/1234567890", "name@example.com"], }, groupPolicy: "allowlist", groups: { "spaces/AAAA": { allow: true, requireMention: true, systemPrompt: "只提供簡短回答。", }, }, actions: { reactions: true }, typingIndicator: "message", mediaMaxMb: 20, }, },}405 Method Not Allowed
Section titled “405 Method Not Allowed”如果在 Google Cloud 日誌看到 405 錯誤,通常代表 Webhook 處理器沒註冊成功。請檢查:
- 設定檔是否正確:執行
openclaw config get channels.googlechat。如果顯示 “Config path not found”,請檢查你的設定。 - Plugin 是否啟用:執行
openclaw plugins list | grep googlechat。如果是 disabled,請在設定中將其開啟。 - 忘記重啟:改完設定後,記得執行
openclaw gateway restart。
你可以透過 openclaw channels status 確認 Google Chat 頻道是否為 enabled 且 configured。
想自動化這套流程?試試 AI Setup Assistant
What’s Next:
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。