@chat-adapter/gchat 4.17.0 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@chat-adapter/gchat)
|
|
4
4
|
[](https://www.npmjs.com/package/@chat-adapter/gchat)
|
|
5
5
|
|
|
6
|
-
Google Chat adapter for [Chat SDK](https://chat-sdk.dev
|
|
6
|
+
Google Chat adapter for [Chat SDK](https://chat-sdk.dev). Configure with service account authentication and optional Pub/Sub.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
|
|
11
|
+
pnpm add @chat-adapter/gchat
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
+
The adapter auto-detects credentials from `GOOGLE_CHAT_CREDENTIALS` or `GOOGLE_CHAT_USE_ADC` environment variables:
|
|
17
|
+
|
|
16
18
|
```typescript
|
|
17
19
|
import { Chat } from "chat";
|
|
18
20
|
import { createGoogleChatAdapter } from "@chat-adapter/gchat";
|
|
@@ -20,9 +22,7 @@ import { createGoogleChatAdapter } from "@chat-adapter/gchat";
|
|
|
20
22
|
const bot = new Chat({
|
|
21
23
|
userName: "mybot",
|
|
22
24
|
adapters: {
|
|
23
|
-
gchat: createGoogleChatAdapter(
|
|
24
|
-
credentials: JSON.parse(process.env.GOOGLE_CHAT_CREDENTIALS!),
|
|
25
|
-
}),
|
|
25
|
+
gchat: createGoogleChatAdapter(),
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -31,9 +31,241 @@ bot.onNewMention(async (thread, message) => {
|
|
|
31
31
|
});
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## Google Chat setup
|
|
35
|
+
|
|
36
|
+
### 1. Create a GCP project
|
|
37
|
+
|
|
38
|
+
1. Go to [console.cloud.google.com](https://console.cloud.google.com)
|
|
39
|
+
2. Click the project dropdown then **New Project**
|
|
40
|
+
3. Enter project name and click **Create**
|
|
41
|
+
|
|
42
|
+
### 2. Enable required APIs
|
|
43
|
+
|
|
44
|
+
Go to **APIs & Services** then **Library** and enable:
|
|
45
|
+
|
|
46
|
+
- **Google Chat API**
|
|
47
|
+
- **Google Workspace Events API** (for receiving all messages)
|
|
48
|
+
- **Cloud Pub/Sub API** (for receiving all messages)
|
|
49
|
+
|
|
50
|
+
### 3. Create a service account
|
|
51
|
+
|
|
52
|
+
1. Go to **IAM & Admin** then **Service Accounts**
|
|
53
|
+
2. Click **Create Service Account**
|
|
54
|
+
3. Enter name and description
|
|
55
|
+
4. Click **Create and Continue**
|
|
56
|
+
5. Skip the optional steps, click **Done**
|
|
57
|
+
|
|
58
|
+
### 4. Create service account key
|
|
59
|
+
|
|
60
|
+
1. Click on your service account
|
|
61
|
+
2. Go to **Keys** tab
|
|
62
|
+
3. Click **Add Key** then **Create new key**
|
|
63
|
+
4. Select **JSON** and click **Create**
|
|
64
|
+
5. Copy the entire JSON content as `GOOGLE_CHAT_CREDENTIALS`
|
|
65
|
+
|
|
66
|
+
> **Note:** If your organization has the `iam.disableServiceAccountKeyCreation` constraint enabled, you need to relax it or add an exception for your project in **IAM & Admin** then **Organization Policies**.
|
|
67
|
+
|
|
68
|
+
### 5. Configure Google Chat app
|
|
69
|
+
|
|
70
|
+
1. Go to the [Chat API configuration](https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat)
|
|
71
|
+
2. Click **Configuration** and fill in:
|
|
72
|
+
- **App name**: Your bot's display name
|
|
73
|
+
- **Avatar URL**: URL to your bot's avatar
|
|
74
|
+
- **Description**: What your bot does
|
|
75
|
+
- **Interactive features**: Enable **Receive 1:1 messages** and **Join spaces and group conversations**
|
|
76
|
+
- **Connection settings**: Select **App URL**
|
|
77
|
+
- **App URL**: `https://your-domain.com/api/webhooks/gchat`
|
|
78
|
+
- **Visibility**: Choose who can discover your app
|
|
79
|
+
3. Click **Save**
|
|
80
|
+
|
|
81
|
+
### 6. Add bot to a space
|
|
82
|
+
|
|
83
|
+
1. Open Google Chat
|
|
84
|
+
2. Create or open a Space
|
|
85
|
+
3. Click the space name then **Manage apps & integrations**
|
|
86
|
+
4. Click **Add apps**, search for your app, and click **Add**
|
|
87
|
+
|
|
88
|
+
## Pub/Sub for all messages (optional)
|
|
89
|
+
|
|
90
|
+
By default, Google Chat only sends webhooks for @mentions. To receive all messages in a space, set up Workspace Events with Pub/Sub.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
createGoogleChatAdapter({
|
|
94
|
+
pubsubTopic: process.env.GOOGLE_CHAT_PUBSUB_TOPIC,
|
|
95
|
+
impersonateUser: process.env.GOOGLE_CHAT_IMPERSONATE_USER,
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`GOOGLE_CHAT_PUBSUB_TOPIC` and `GOOGLE_CHAT_IMPERSONATE_USER` are also auto-detected from env vars, so you can omit them from config if the env vars are set.
|
|
100
|
+
|
|
101
|
+
### 1. Create Pub/Sub topic
|
|
102
|
+
|
|
103
|
+
1. Go to **Pub/Sub** then **Topics**
|
|
104
|
+
2. Click **Create Topic**
|
|
105
|
+
3. Enter topic ID (e.g., `chat-events`)
|
|
106
|
+
4. Uncheck **Add a default subscription**
|
|
107
|
+
5. Click **Create**
|
|
108
|
+
6. Copy the full topic name as `GOOGLE_CHAT_PUBSUB_TOPIC` (format: `projects/your-project-id/topics/chat-events`)
|
|
109
|
+
|
|
110
|
+
### 2. Grant Chat service account access
|
|
111
|
+
|
|
112
|
+
1. Go to your Pub/Sub topic
|
|
113
|
+
2. Click **Permissions** tab
|
|
114
|
+
3. Click **Add Principal**
|
|
115
|
+
4. Enter `chat-api-push@system.gserviceaccount.com`
|
|
116
|
+
5. Select role **Pub/Sub Publisher**
|
|
117
|
+
6. Click **Save**
|
|
118
|
+
|
|
119
|
+
### 3. Create push subscription
|
|
120
|
+
|
|
121
|
+
1. Go to **Pub/Sub** then **Subscriptions**
|
|
122
|
+
2. Click **Create Subscription**
|
|
123
|
+
3. Select your topic
|
|
124
|
+
4. Set **Delivery type** to Push
|
|
125
|
+
5. Set **Endpoint URL** to `https://your-domain.com/api/webhooks/gchat`
|
|
126
|
+
6. Click **Create**
|
|
127
|
+
|
|
128
|
+
### 4. Enable domain-wide delegation
|
|
129
|
+
|
|
130
|
+
Domain-wide delegation is required for creating Workspace Events subscriptions and initiating DMs.
|
|
131
|
+
|
|
132
|
+
**Step 1 — Enable delegation on the service account:**
|
|
133
|
+
|
|
134
|
+
1. Go to **IAM & Admin** then **Service Accounts**
|
|
135
|
+
2. Click on your service account
|
|
136
|
+
3. Check **Enable Google Workspace Domain-wide Delegation** and save
|
|
137
|
+
4. Copy the **Client ID** (a numeric ID, not the email)
|
|
138
|
+
|
|
139
|
+
**Step 2 — Authorize in Google Admin Console:**
|
|
140
|
+
|
|
141
|
+
1. Go to [Google Admin Console](https://admin.google.com)
|
|
142
|
+
2. Go to **Security** then **Access and data control** then **API controls**
|
|
143
|
+
3. Click **Manage Domain Wide Delegation** then **Add new**
|
|
144
|
+
4. Enter the numeric **Client ID** from Step 1
|
|
145
|
+
5. Add OAuth scopes (comma-separated, on one line):
|
|
146
|
+
```
|
|
147
|
+
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
|
|
148
|
+
```
|
|
149
|
+
6. Click **Authorize**
|
|
150
|
+
|
|
151
|
+
**Step 3 — Set environment variable:**
|
|
152
|
+
|
|
153
|
+
Set `GOOGLE_CHAT_IMPERSONATE_USER` to an admin user email in your domain (e.g., `admin@yourdomain.com`).
|
|
154
|
+
|
|
155
|
+
## Configuration
|
|
156
|
+
|
|
157
|
+
All options are auto-detected from environment variables when not provided.
|
|
158
|
+
|
|
159
|
+
| Option | Required | Description |
|
|
160
|
+
|--------|----------|-------------|
|
|
161
|
+
| `credentials` | No* | Service account credentials JSON. Auto-detected from `GOOGLE_CHAT_CREDENTIALS` |
|
|
162
|
+
| `useApplicationDefaultCredentials` | No | Use Application Default Credentials. Auto-detected from `GOOGLE_CHAT_USE_ADC` |
|
|
163
|
+
| `pubsubTopic` | No | Pub/Sub topic for Workspace Events. Auto-detected from `GOOGLE_CHAT_PUBSUB_TOPIC` |
|
|
164
|
+
| `impersonateUser` | No | User email for domain-wide delegation. Auto-detected from `GOOGLE_CHAT_IMPERSONATE_USER` |
|
|
165
|
+
| `auth` | No | Custom auth object (advanced) |
|
|
166
|
+
| `logger` | No | Logger instance (defaults to `ConsoleLogger("info")`) |
|
|
167
|
+
|
|
168
|
+
*Either `credentials`, `GOOGLE_CHAT_CREDENTIALS` env var, `useApplicationDefaultCredentials`, or `GOOGLE_CHAT_USE_ADC=true` is required.
|
|
169
|
+
|
|
170
|
+
## Environment variables
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
GOOGLE_CHAT_CREDENTIALS={"type":"service_account",...}
|
|
174
|
+
|
|
175
|
+
# Optional: for receiving all messages
|
|
176
|
+
GOOGLE_CHAT_PUBSUB_TOPIC=projects/your-project/topics/chat-events
|
|
177
|
+
GOOGLE_CHAT_IMPERSONATE_USER=admin@yourdomain.com
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Features
|
|
181
|
+
|
|
182
|
+
### Messaging
|
|
183
|
+
|
|
184
|
+
| Feature | Supported |
|
|
185
|
+
|---------|-----------|
|
|
186
|
+
| Post message | Yes |
|
|
187
|
+
| Edit message | Yes |
|
|
188
|
+
| Delete message | Yes |
|
|
189
|
+
| File uploads | No |
|
|
190
|
+
| Streaming | Post+Edit fallback |
|
|
191
|
+
|
|
192
|
+
### Rich content
|
|
193
|
+
|
|
194
|
+
| Feature | Supported |
|
|
195
|
+
|---------|-----------|
|
|
196
|
+
| Card format | Google Chat Cards |
|
|
197
|
+
| Buttons | Yes |
|
|
198
|
+
| Link buttons | Yes |
|
|
199
|
+
| Select menus | Yes |
|
|
200
|
+
| Tables | ASCII |
|
|
201
|
+
| Fields | Yes |
|
|
202
|
+
| Images in cards | Yes |
|
|
203
|
+
| Modals | No |
|
|
204
|
+
|
|
205
|
+
### Conversations
|
|
206
|
+
|
|
207
|
+
| Feature | Supported |
|
|
208
|
+
|---------|-----------|
|
|
209
|
+
| Slash commands | No |
|
|
210
|
+
| Mentions | Yes |
|
|
211
|
+
| Add reactions | Yes (via Workspace Events) |
|
|
212
|
+
| Remove reactions | Yes (via Workspace Events) |
|
|
213
|
+
| Typing indicator | No |
|
|
214
|
+
| DMs | Yes (requires delegation) |
|
|
215
|
+
| Ephemeral messages | Yes (native) |
|
|
216
|
+
|
|
217
|
+
### Message history
|
|
218
|
+
|
|
219
|
+
| Feature | Supported |
|
|
220
|
+
|---------|-----------|
|
|
221
|
+
| Fetch messages | Yes |
|
|
222
|
+
| Fetch single message | No |
|
|
223
|
+
| Fetch thread info | Yes |
|
|
224
|
+
| Fetch channel messages | Yes |
|
|
225
|
+
| List threads | Yes |
|
|
226
|
+
| Fetch channel info | Yes |
|
|
227
|
+
| Post channel message | Yes |
|
|
228
|
+
|
|
229
|
+
## Limitations
|
|
230
|
+
|
|
231
|
+
- **Typing indicators**: Not supported by Google Chat API. `startTyping()` is a no-op.
|
|
232
|
+
- **Adding reactions**: The Google Chat API doesn't support service account (app) authentication for adding reactions. To use `addReaction()` or `removeReaction()`, you need domain-wide delegation with `impersonateUser` configured — but the reaction appears as coming from the impersonated user, not the bot.
|
|
233
|
+
|
|
234
|
+
### Message history (`fetchMessages`)
|
|
235
|
+
|
|
236
|
+
Fetching message history requires domain-wide delegation with the `impersonateUser` config option set. The impersonated user must have access to the spaces you want to read from. See the [Pub/Sub setup](#4-enable-domain-wide-delegation) above for configuring delegation and OAuth scopes.
|
|
237
|
+
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
### No webhook received
|
|
241
|
+
|
|
242
|
+
- Verify the App URL is correct in Google Chat configuration
|
|
243
|
+
- Check that the Chat API is enabled
|
|
244
|
+
- Ensure the service account has the necessary permissions
|
|
245
|
+
|
|
246
|
+
### Pub/Sub not working
|
|
247
|
+
|
|
248
|
+
- Verify `chat-api-push@system.gserviceaccount.com` has Pub/Sub Publisher role
|
|
249
|
+
- Check that the push subscription URL is correct
|
|
250
|
+
- Verify domain-wide delegation is configured with correct scopes
|
|
251
|
+
- Check `GOOGLE_CHAT_IMPERSONATE_USER` is a valid admin email
|
|
252
|
+
|
|
253
|
+
### "Permission denied" for Workspace Events
|
|
254
|
+
|
|
255
|
+
- Ensure domain-wide delegation is configured
|
|
256
|
+
- Verify the OAuth scopes are exactly as specified
|
|
257
|
+
- Check that the impersonated user has access to the spaces
|
|
258
|
+
|
|
259
|
+
### "Insufficient Permission" for DMs
|
|
260
|
+
|
|
261
|
+
- DMs require domain-wide delegation with `chat.spaces` and `chat.spaces.create` scopes
|
|
262
|
+
- Scope changes can take up to 24 hours to propagate
|
|
263
|
+
|
|
264
|
+
### Button clicks not received
|
|
35
265
|
|
|
36
|
-
|
|
266
|
+
- Verify **Interactive features** is enabled in the Google Chat app configuration
|
|
267
|
+
- Check that the App URL is correctly set and accessible
|
|
268
|
+
- Button clicks go to the same webhook URL as messages
|
|
37
269
|
|
|
38
270
|
## License
|
|
39
271
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chat-adapter/gchat",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "Google Chat adapter for chat",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@googleapis/chat": "^44.6.0",
|
|
20
20
|
"@googleapis/workspaceevents": "^9.1.0",
|
|
21
|
-
"@chat-adapter/shared": "4.
|
|
22
|
-
"chat": "4.
|
|
21
|
+
"@chat-adapter/shared": "4.19.0",
|
|
22
|
+
"chat": "4.19.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^25.3.2",
|