Google Chat(Chat API)
状态:准备好通过 Google Chat API webhooks 进行 DMs + spaces(仅 HTTP)。
快速设置(初学者)
- 创建 Google Cloud 项目并启用 Google Chat API。
- 前往:Google Chat API 凭证
- 如果尚未启用,请启用该 API。
- 创建一个 Service Account:
- 按 Create Credentials > Service Account。
- 随意命名(例如
openclaw-chat)。 - 保留权限空白(按 Continue)。
- 保留有访问权限的主体空白(按 Done)。
- 创建并下载 JSON Key:
- 在服务账户列表中,点击你刚刚创建的那个。
- 进入 Keys 标签。
- 按 Add Key > Create new key。
- 选择 JSON 并按 Create。
- 在你的网关上存储下载的 JSON 文件(例如
~/.openclaw/googlechat-service-account.json)。 - 在 Google Cloud Console Chat Configuration 中创建 Google Chat 应用:
- 填写 Application info:
- App name:(例如
OpenClaw) - Avatar URL:(例如
https://molt.bot/logo.png) - Description:(例如
Personal AI Assistant)
- App name:(例如
- 启用 Interactive features。
- 在 Functionality 下,检查 Join spaces and group conversations。
- 在 Connection settings 下,选择 HTTP endpoint URL。
- 在 Triggers 下,选择 Use a common HTTP endpoint URL for all triggers 并将其设置为你的网关公共 URL 后面跟着
/googlechat。- 提示:运行
openclaw status查找你的网关公共 URL。
- 提示:运行
- 在 Visibility 下,检查 Make this Chat app available to specific people and groups in <Your Domain>。
- 在文本框中输入你的电子邮件地址(例如
user@example.com)。 - 按底部的 Save。
- 填写 Application info:
- 启用应用状态:
- 保存后,刷新页面。
- 查找 App status 部分(通常在保存后在顶部或底部附近)。
- 将状态更改为 Live - available to users。
- 再次按 Save。
- 使用服务账户路径 + webhook 受众配置 OpenClaw:
- 环境:
GOOGLE_CHAT_SERVICE_ACCOUNT_FILE=/path/to/service-account.json - 或配置:
channels.googlechat.serviceAccountFile: "/path/to/service-account.json"。
- 环境:
- 设置 webhook 受众类型 + 值(匹配你的 Chat 应用配置)。
- 启动网关。Google Chat 将 POST 到你的 webhook 路径。
添加到 Google Chat
一旦网关运行并且你的电子邮件被添加到可见性列表:
- 前往 Google Chat。
- 点击 Direct Messages 旁边的 +(加号)图标。
- 在搜索栏中(你通常添加人员的地方),输入你在 Google Cloud Console 中配置的 App name。
- 注意:机器人不会出现在"Marketplace"浏览列表中,因为它是一个私有应用。你必须按名称搜索它。
- 从结果中选择你的机器人。
- 按 Add 或 Chat 开始 1:1 对话。
- 发送"Hello"来触发助手!
公共 URL(仅限 Webhook)
Google Chat webhooks 需要公共 HTTPS 端点。为安全起见,只向互联网公开 /googlechat 路径。将 OpenClaw 仪表板和其他敏感端点保留在你的专用网络上。
选项 A:Tailscale Funnel(推荐)
对私有仪表板使用 Tailscale Serve,对公共 webhook 路径使用 Funnel。这保持 / 私有,同时只暴露 /googlechat。
检查你的网关绑定到什么地址:
bashss -tlnp | grep 18789记下 IP 地址(例如
127.0.0.1、0.0.0.0,或你的 Tailscale IP 如100.x.x.x)。仅向 tailnet 公开仪表板(端口 8443):
bash# 如果绑定到 localhost(127.0.0.1 或 0.0.0.0): tailscale serve --bg --https 8443 http://127.0.0.1:18789 # 如果仅绑定到 Tailscale IP(例如 100.106.161.80): tailscale serve --bg --https 8443 http://100.106.161.80:18789仅公开 webhook 路径:
bash# 如果绑定到 localhost(127.0.0.1 或 0.0.0.0): tailscale funnel --bg --set-path /googlechat http://127.0.0.1:18789/googlechat # 如果仅绑定到 Tailscale IP(例如 100.106.161.80): tailscale funnel --bg --set-path /googlechat http://100.106.161.80:18789/googlechat授权节点以进行 Funnel 访问: 如果提示,访问输出中显示的授权 URL 以在你的 tailnet 策略中为此节点启用 Funnel。
验证配置:
bashtailscale serve status tailscale funnel status
你的公共 webhook URL 将是: https://<node-name>.<tailnet>.ts.net/googlechat
你的私有仪表板保持 tailnet 专用: https://<node-name>.<tailnet>.ts.net:8443/
在 Google Chat 应用配置中使用公共 URL(不带 :8443)。
注意:此配置在重启后保持不变。要稍后删除它,运行
tailscale funnel reset和tailscale serve reset。
选项 B:反向代理(Caddy)
如果你使用像 Caddy 这样的反向代理,只代理特定路径:
your-domain.com {
reverse_proxy /googlechat* localhost:18789
}使用此配置,任何对 your-domain.com/ 的请求都将被忽略或返回 404,而 your-domain.com/googlechat 被安全地路由到 OpenClaw。
选项 C:Cloudflare Tunnel
配置你的隧道入口规则以仅路由 webhook 路径:
- 路径:
/googlechat->http://localhost:18789/googlechat - 默认规则:HTTP 404(未找到)
它如何工作
- Google Chat 将 webhook POST 发送到网关。每个请求包含一个
Authorization: Bearer <token>头。 - OpenClaw 根据配置的
audienceType+audience验证令牌:audienceType: "app-url"-> 受众是你的 HTTPS webhook URL。audienceType: "project-number"-> 受众是云项目编号。
- 消息按 space 路由:
- DMs 使用会话键
agent:<agentId>:googlechat:dm:<spaceId>。 - Spaces 使用会话键
agent:<agentId>:googlechat:group:<spaceId>。
- DMs 使用会话键
- DM 访问默认是配对的。未知发送者收到配对码;批准方式:
openclaw pairing approve googlechat <code>
- 群组空间默认需要 @-提及。如果提及检测需要应用的用户名,使用
botUser。
目标
使用这些标识符进行发送和允许列表:
- 直接消息:
users/<userId>或users/<email>(接受电子邮件地址)。 - Spaces:
spaces/<spaceId>。
配置亮点
{
channels: {
"googlechat": {
enabled: true,
serviceAccountFile: "/path/to/service-account.json",
audienceType: "app-url",
audience: "https://gateway.example.com/googlechat",
webhookPath: "/googlechat",
botUser: "users/1234567890", // 可选;帮助提及检测
dm: {
policy: "pairing",
allowFrom: ["users/1234567890", "name@example.com"]
},
groupPolicy: "allowlist",
groups: {
"spaces/AAAA": {
allow: true,
requireMention: true,
users: ["users/1234567890"],
systemPrompt: "Short answers only."
}
},
actions: { reactions: true },
typingIndicator: "message",
mediaMaxMb: 20
}
}
}注意:
- 服务账户凭证也可以通过
serviceAccount(JSON 字符串)内联传递。 - 如果未设置
webhookPath,默认 webhook 路径为/googlechat。 - 当启用
actions.reactions时,可以通过reactions工具和channels action使用反应。 typingIndicator支持none、message(默认)和reaction(反应需要用户 OAuth)。- 附件通过 Chat API 下载并存储在媒体管道中(大小由
mediaMaxMb限制)。
故障排除
405 Method Not Allowed
如果 Google Cloud Logs Explorer 显示如下错误:
status code: 405, reason phrase: HTTP error response: HTTP/1.1 405 Method Not Allowed这意味着 webhook 处理器未注册。常见原因:
通道未配置:
channels.googlechat部分从你的配置中缺失。用以下命令验证:bashopenclaw config get channels.googlechat如果它返回"Config path not found",添加配置(见配置亮点)。
插件未启用:检查插件状态:
bashopenclaw plugins list | grep googlechat如果显示"disabled",在你的配置中添加
plugins.entries.googlechat.enabled: true。网关未重启:添加配置后,重启网关:
bashopenclaw gateway restart
验证通道正在运行:
openclaw channels status
# 应该显示:Google Chat default: enabled, configured, ...其他问题
- 检查
openclaw channels status --probe是否有认证错误或缺失的受众配置。 - 如果没有消息到达,确认 Chat 应用的 webhook URL + 事件订阅。
- 如果提及门控阻止回复,设置
botUser为应用的用户资源名称并验证requireMention。 - 发送测试消息时使用
openclaw logs --follow查看请求是否到达网关。
相关文档: