Google Chat 是 Google Workspace 的企业通讯平台。OpenClaw 通过 Google Chat API 的 Webhook 模式接入,支持私信和 Spaces(群组)。由于 Google Chat 需要公网 HTTPS 端点,本文重点介绍三种安全暴露方案。
配置概览
Google Chat 接入是内置功能,无需安装插件,但需要:
- Google Cloud 项目 + Google Chat API 已启用
- 服务账号(Service Account)JSON 密钥
- 公网可访问的 HTTPS Webhook URL
第一步:创建 Google Cloud 服务账号
- 打开 Google Chat API 凭据页面
- 若 API 未启用,先点击启用
- 点击 Create Credentials → Service Account
- 填写名称(如
openclaw-chat),权限和访问者留空,直接完成 - 在服务账号列表中点击刚创建的账号,进入 Keys 标签
- 点击 Add Key → Create new key,选择 JSON,下载密钥文件
- 将文件存放到 Gateway 主机(如
~/.openclaw/googlechat-service-account.json)
第二步:创建 Google Chat 应用
打开 Google Cloud Console Chat 配置页面:
- App name:如
OpenClaw - Avatar URL:如
https://openclaw.ai/logo.png - Description:如
Personal AI Assistant - 勾选 Interactive features
- 功能(Functionality)中勾选 Join spaces and group conversations
- Connection settings 选择 HTTP endpoint URL
- Triggers 选 Use a common HTTP endpoint URL for all triggers,填入你的 Gateway 公网地址 +
/googlechat - Visibility 中填入你的邮箱,保存
- 保存后刷新页面,找到 App status,改为 Live - available to users,再次保存
第三步:配置 OpenClaw
{
"channels": {
"googlechat": {
"enabled": true,
"serviceAccountFile": "/path/to/service-account.json"
}
}
}或使用环境变量:
export GOOGLE_CHAT_SERVICE_ACCOUNT_FILE="/path/to/service-account.json"第四步:暴露公网 Webhook(三选一)
⚠️ 安全原则:只暴露
/googlechat路径,不要把 OpenClaw 控制台等其他端点暴露到公网。
方案 A:Tailscale Funnel(推荐)
Tailscale Funnel 只暴露指定路径,控制台保持内网访问:
# 查看 Gateway 绑定地址
ss -tlnp | grep 18789
# 将控制面板暴露到 tailnet(私有,端口 8443)
tailscale serve --bg --https 8443 http://127.0.0.1:18789
# 只将 /googlechat 路径暴露到公网
tailscale funnel --bg --set-path /googlechat http://127.0.0.1:18789/googlechat
# 验证配置
tailscale serve status
tailscale funnel status公网 Webhook URL:https://<node>.<tailnet>.ts.net/googlechat
控制台 URL(仅内网):https://<node>.<tailnet>.ts.net:8443/
配置跨重启持久,清除时运行
tailscale funnel reset和tailscale serve reset。
方案 B:Caddy 反向代理
your-domain.com {
reverse_proxy /googlechat localhost:18789
}方案 C:Cloudflare Tunnel
cloudflared tunnel create openclaw
cloudflared tunnel route dns openclaw your-domain.com配置 config.yml 将 /googlechat 路由到本地 Gateway。
添加 Bot 到 Google Chat
- 打开 Google Chat
- 点击 Direct Messages 旁边的 +
- 在搜索框输入你配置的 App name
注意:这是私有 App,不会出现在 Marketplace 浏览列表,必须按名称精确搜索。
- 选中 Bot,点击 Add 或 Chat
- 发送一条消息触发 Agent
工作原理
Google Chat 通过 HTTP POST 向 Gateway 发送消息事件,Gateway 验证请求签名后路由给 Agent 处理,Agent 通过 Chat API(使用服务账号认证)回复消息。
消息目标格式
发送主动消息时使用:
| 目标格式 | 说明 |
|---|---|
space:<space_id> | 发送到指定 Space |
dm:<user_id> | 发送到用户私信 |
常见问题
收到 405 Method Not Allowed?
检查 Webhook URL 路径是否正确(应为 /googlechat),以及 Connection settings 中是否选择了正确的触发器类型。
Bot 搜索不到? App status 必须是 Live,且你的邮箱已添加到 Visibility 列表。私有 App 不显示在 Marketplace,只能按名称搜索。
原文:Google Chat - OpenClaw | 来源:OpenClaw 官方文档