Google Chat
Integrate with Google Chat spaces for team collaboration and automated workflows.
Install
pnpm add @chat-adapter/gchatQuick start
The adapter auto-detects GOOGLE_CHAT_CREDENTIALS (or GOOGLE_CHAT_USE_ADC) from the environment.
import { Chat } from "chat";
import { createGoogleChatAdapter } from "@chat-adapter/gchat";
const bot = new Chat({
userName: "mybot",
adapters: {
gchat: createGoogleChatAdapter(),
},
});
bot.onNewMention(async (thread, message) => {
await thread.post("Hello from Google Chat!");
});Configuration
Prop
Type
One of googleChatProjectNumber, pubsubAudience, or disableSignatureVerification: true is required — the constructor throws otherwise. Configure the verifier(s) for each transport you actually receive.
Authentication
1. Create a GCP project
- Go to console.cloud.google.com and create a project.
- Enable Google Chat API, Google Workspace Events API (for receiving all messages), and Cloud Pub/Sub API.
2. Create a service account
- Open IAM & Admin then Service Accounts and click Create Service Account.
- After creation, open the account and go to the Keys tab.
- Click Add Key then Create new key then JSON.
- Copy the JSON to
GOOGLE_CHAT_CREDENTIALS.
If your organization has the iam.disableServiceAccountKeyCreation constraint enabled, you need to relax it or add a project exception under IAM & Admin then Organization Policies.
3. Configure the Chat app
- Open the Chat API configuration.
- Fill in app name, avatar, description.
- Enable Receive 1:1 messages and Join spaces and group conversations.
- Set connection settings to App URL with
https://your-domain.com/api/webhooks/gchat. - Set visibility, then save.
4. Add the bot to a space
- Open Google Chat.
- In a Space, open Manage apps & integrations then Add apps and find your app.
Advanced
Pub/Sub for receiving all messages
By default, Google Chat only sends webhooks for @mentions. To receive all messages in a space, set up Workspace Events with Pub/Sub.
createGoogleChatAdapter({
pubsubTopic: process.env.GOOGLE_CHAT_PUBSUB_TOPIC,
impersonateUser: process.env.GOOGLE_CHAT_IMPERSONATE_USER,
});Topic & subscription:
- Under Pub/Sub then Topics, create a topic (e.g.
chat-events) and copy its full name toGOOGLE_CHAT_PUBSUB_TOPIC. - Add
chat-api-push@system.gserviceaccount.comas a Pub/Sub Publisher. - Create a Push subscription with endpoint
https://your-domain.com/api/webhooks/gchat.
Domain-wide delegation:
Required for Workspace Events subscriptions and initiating DMs.
- In IAM & Admin then Service Accounts, edit your service account and check Enable Google Workspace Domain-wide Delegation. Copy the numeric Client ID.
- In the Google Admin Console, go to Security then Access and data control then API controls, then Manage Domain Wide Delegation.
- Add the Client ID with these comma-separated scopes:
https://www.googleapis.com/auth/chat.spaces.readonly, https://www.googleapis.com/auth/chat.messages.readonly, https://www.googleapis.com/auth/chat.spaces, https://www.googleapis.com/auth/chat.spaces.create - Set
GOOGLE_CHAT_IMPERSONATE_USERto an admin email.
Webhook verification
The two transports share one HTTP endpoint, so each verifier only covers its own request shape:
- Direct webhooks — Google Chat sends a signed JWT whose
audclaim is your GCP project number. Configure withgoogleChatProjectNumber. - Pub/Sub push — Cloud Pub/Sub sends a signed OIDC JWT whose audience is whatever you configured on the push subscription. Configure with
pubsubAudience.
If you only configure googleChatProjectNumber, incoming Pub/Sub-shaped requests are rejected with HTTP 401 — and vice versa. Configure both if you receive both.
Limitations
- Typing indicators — not supported by the Google Chat API.
- Adding reactions — the Chat API doesn't allow service-account auth for reactions. With
impersonateUserconfigured, the reaction appears as coming from the impersonated user. - Message history (
fetchMessages) — requires domain-wide delegation withimpersonateUser.
Feature support
Messaging
| Feature | Supported |
|---|---|
| Post message | |
| Edit message | |
| Delete message | |
| File uploads | |
| Streaming | Post+Edit |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | Google Chat Cards |
| Buttons | |
| Link buttons | |
| Select menus | |
| Tables | ASCII |
| Fields | |
| Images in cards | |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | |
| Add reactions | Workspace Events |
| Remove reactions | Workspace Events |
| Typing indicator | |
| DMs | Requires delegation |
| Ephemeral messages | Native |
| User lookup | Cached |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | Requires delegation |
| Fetch single message | |
| Fetch thread info | |
| Fetch channel messages | |
| List threads | |
| Fetch channel info | |
| Post channel message |