mirror of
https://github.com/vercel/chat.git
synced 2026-09-14 18:32:29 +08:00
3c4e07973c
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@chat-adapter/gchat
Google Chat adapter for the chat SDK.
Installation
npm install chat @chat-adapter/gchat
Usage
import { Chat } from "chat";
import { createGoogleChatAdapter } from "@chat-adapter/gchat";
const chat = new Chat({
userName: "mybot",
adapters: {
gchat: createGoogleChatAdapter({
credentials: JSON.parse(process.env.GOOGLE_CHAT_CREDENTIALS!),
}),
},
});
// Handle @mentions
chat.onNewMention(async (thread, message) => {
await thread.post("Hello from Google Chat!");
});
Configuration
| Option | Required | Description |
|---|---|---|
credentials |
Yes* | Service account credentials JSON |
useADC |
No | Use Application Default Credentials instead |
pubsubTopic |
No | Pub/Sub topic for Workspace Events |
impersonateUser |
No | User email for domain-wide delegation |
*Either credentials or useADC: true is required.
Setup
1. Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select existing
- Enable the Google Chat API
2. Create a Service Account
- Go to IAM & Admin → Service Accounts
- Create a new service account
- Download the JSON key file
- Set as
GOOGLE_CHAT_CREDENTIALSenvironment variable
3. Configure Chat App
- Go to Google Chat API Configuration
- Configure your app:
- App name and avatar
- HTTP endpoint URL for webhooks
- Enable interactive features
4. (Optional) Pub/Sub for Workspace Events
For reaction events, you need Workspace Events via Pub/Sub:
- Enable Pub/Sub API and Workspace Events API
- Create a Pub/Sub topic
- Set
pubsubTopicin adapter options - Configure subscription to your webhook endpoint
Features
- Message posting and editing
- Thread subscriptions
- Reaction events (via Workspace Events)
- File attachments
- Rich cards (Google Chat Cards)
- Action callbacks (card buttons)
- Direct messages
- Space management
Limitations
- Typing indicators: Not supported by Google Chat API
- Adding reactions: Requires domain-wide delegation (appears from impersonated user, not bot)
License
MIT