Google Chat 是 OpenClaw 的可下载插件,通过 HTTP webhook 支持 DM 和 Space。

安装

openclaw plugins install @openclaw/googlechat

配置步骤

  1. 在 Google Cloud 创建项目并启用 Google Chat API
  2. 创建 Service Account 并下载 JSON 密钥文件
  3. 在 Google Cloud Console Chat Configuration 创建 Chat app:
    • 填写 App name、Avatar URL、Description
    • 启用 Interactive features
    • Connection settings 选择 HTTP endpoint URL
    • 设置 webhook URL(openclaw status 查看 gateway 公网 URL)
  4. 将 App status 改为 Live - available to users
  5. 配置 OpenClaw:
{
  channels: {
    googlechat: {
      enabled: true,
      serviceAccountFile: "/path/to/service-account.json",
      audienceType: "app-url",
      audience: "https://gateway.example.com/googlechat",
      webhookPath: "/googlechat",
      dm: { policy: "pairing" },
      groupPolicy: "allowlist",
    },
  },
}

环境变量:GOOGLE_CHAT_SERVICE_ACCOUNT_FILE

公网 URL 暴露方式

Google Chat webhook 需要公网 HTTPS 端点,建议只暴露 /googlechat 路径:

Tailscale Funnel(推荐):

tailscale serve --bg --https 8443 http://127.0.0.1:18789
tailscale funnel --bg --set-path /googlechat http://127.0.0.1:18789/googlechat

Caddy 反向代理:

your-domain.com {
    reverse_proxy /googlechat* localhost:18789
}

工作原理

  1. Google Chat 向 gateway 发送 webhook POST,携带 Authorization: Bearer <token>
  2. OpenClaw 验证 token(audienceType: "app-url" 或 "project-number")
  3. 消息按 space 路由:
    • DM:agent:<agentId>:googlechat:direct:<spaceId>
    • Space:agent:<agentId>:googlechat:group:<spaceId>
  4. DM 默认使用 pairing 模式

目标格式

  • 私信:users/<userId>(推荐)
  • Space:spaces/<spaceId>
  • 邮件(不推荐,可变):需设 dangerouslyAllowNameMatching: true

完整配置示例

{
  channels: {
    googlechat: {
      enabled: true,
      serviceAccountFile: "/path/to/service-account.json",
      audienceType: "app-url",
      audience: "https://gateway.example.com/googlechat",
      botUser: "users/1234567890",
      dm: {
        policy: "pairing",
        allowFrom: ["users/1234567890"],
      },
      groupPolicy: "allowlist",
      groups: {
        "spaces/AAAA": {
          enabled: true,
          requireMention: true,
          users: ["users/1234567890"],
        },
      },
      actions: { reactions: true },
      typingIndicator: "message",
      mediaMaxMb: 20,
    },
  },
}

故障排查

405 Method Not Allowed:

  • 检查 channels.googlechat 配置是否存在
  • 检查插件是否启用:openclaw plugins list | grep googlechat
  • 重启 gateway:openclaw gateway restart

其他问题:

  • openclaw channels status --probe 检查认证错误
  • openclaw logs --follow 查看实时日志

相关链接