@mercury-fw/channel-google-chat 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +49 -6
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mercury-fw/channel-google-chat
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 5e09c69: - README: a section on connecting a new app to a Chat app that already exists (finding the service account and the subscription, creating a key, `mfw google-chat set-key`).
8
+ - README: how to list and delete the keys the old instances left behind, before the service account reaches its limit of 10.
9
+ - README: `--project` on the `keys create` command of the setup.
10
+
11
+ ## 0.1.2
12
+
13
+ ### Patch Changes
14
+
15
+ - ab52977: An app created with the Google Chat channel trusts `protobufjs` in `trustedDependencies`, so its install no longer reports that package's postinstall as blocked. The channel's README says to do the same when adding it by hand.
16
+
3
17
  ## 0.1.1
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -6,6 +6,12 @@ Puts a [Mercury](https://github.com/lucabro81/mercury-fw) agent on Google Chat a
6
6
  bun add @mercury-fw/channel-google-chat
7
7
  ```
8
8
 
9
+ Added by hand (an app made with `mfw create` has this already), the channel brings in `protobufjs` (through Google's Pub/Sub client), whose install script Bun blocks unless the app trusts it, so add it to `trustedDependencies` in the app's `package.json`:
10
+
11
+ ```json
12
+ "trustedDependencies": ["protobufjs"]
13
+ ```
14
+
9
15
  ```ts
10
16
  import { googleChatChannel } from "@mercury-fw/channel-google-chat";
11
17
 
@@ -29,6 +35,7 @@ channels: [googleChatChannel],
29
35
  - [6. Configure the consent screen (Cloud Console)](#6-configure-the-consent-screen-cloud-console)
30
36
  - [7. Configure the Chat app (Cloud Console)](#7-configure-the-chat-app-cloud-console)
31
37
  - [8. Start and try it](#8-start-and-try-it)
38
+ - [Connecting an app to an existing Chat app](#connecting-an-app-to-an-existing-chat-app)
32
39
  - [When the subscription disappears](#when-the-subscription-disappears)
33
40
 
34
41
  ## Setting up the Chat app
@@ -39,7 +46,7 @@ Everything goes through `gcloud` except two pages of Cloud Console (steps 6 and
39
46
 
40
47
  - a Google Workspace Business or Enterprise account: Chat apps don't exist for personal Gmail accounts;
41
48
  - `gcloud` logged in with that account (`gcloud auth login <you@company.com>`), allowed to create projects and link a billing account;
42
- - the app with its dependencies installed (`bun install`), for `bunx mfw` in step 5.
49
+ - the app with its dependencies installed (`bun install`), for `mfw` in step 5.
43
50
 
44
51
  ### 1. Name things
45
52
 
@@ -94,7 +101,7 @@ gcloud pubsub subscriptions add-iam-policy-binding "$SUBSCRIPTION" \
94
101
  --project="$PROJECT_ID" \
95
102
  --member="serviceAccount:${SA_EMAIL}" \
96
103
  --role="roles/pubsub.subscriber"
97
- gcloud iam service-accounts keys create key.json --iam-account="$SA_EMAIL"
104
+ gcloud iam service-accounts keys create key.json --iam-account="$SA_EMAIL" --project="$PROJECT_ID"
98
105
  ```
99
106
 
100
107
  A service account takes a few seconds to become visible to the rest of Google Cloud: if the binding fails saying the account doesn't exist, wait a moment and run it again.
@@ -102,7 +109,7 @@ A service account takes a few seconds to become visible to the rest of Google Cl
102
109
  Then, from the app's folder, write the key and the subscription into its `.env` with the app's own CLI, and delete the key file. The command replaces the lines `mfw create` left empty (or an older key), puts the private key on one line the way the channel reads it, and never prints it:
103
110
 
104
111
  ```bash
105
- bunx mfw google-chat set-key key.json --subscription "projects/${PROJECT_ID}/subscriptions/${SUBSCRIPTION}"
112
+ mfw google-chat set-key key.json --subscription "projects/${PROJECT_ID}/subscriptions/${SUBSCRIPTION}"
106
113
  rm key.json
107
114
  ```
108
115
 
@@ -133,14 +140,50 @@ Click **Save**. The field names here come from Google's own Pub/Sub quickstart;
133
140
 
134
141
  ### 8. Start and try it
135
142
 
136
- Start the app (`bunx mfw start`) and check that the channel came up without errors:
143
+ Start the app (`mfw start`) and check that the channel came up without errors:
137
144
 
138
145
  ```bash
139
- bunx mfw logs mercury
146
+ mfw logs mercury
140
147
  ```
141
148
 
142
149
  `[channel] google-chat started` with no `pubsub stream error` after it means Mercury is pulling from the subscription. Then, in Google Chat, start a new chat and search the app's name (it shows up only for the people and groups in **Visibility**), or add it to a space; write to it and it answers.
143
150
 
151
+ ## Connecting an app to an existing Chat app
152
+
153
+ When the Chat app is already set up and the Mercury instance behind it changes (the app scaffolded again, or moved to another machine), the new app only needs a key of the service account and the subscription's name in its `.env`. It replaces the old instance, it doesn't run next to it: stop the old one first, two instances on one subscription split the conversations between them.
154
+
155
+ If you don't have the project's id at hand, `gcloud projects list` shows it; then the service account and the subscription:
156
+
157
+ ```bash
158
+ PROJECT_ID=<the project's id>
159
+ gcloud iam service-accounts list --project="$PROJECT_ID"
160
+ gcloud pubsub subscriptions list --project="$PROJECT_ID" --format="value(name)"
161
+ ```
162
+
163
+ ```bash
164
+ SA_EMAIL=<the EMAIL column of the service account Mercury runs as>
165
+ SUBSCRIPTION=<the part after subscriptions/>
166
+ ```
167
+
168
+ Then, from the new app's folder, create a key, write it into the `.env` with the subscription, and delete the key file:
169
+
170
+ ```bash
171
+ gcloud iam service-accounts keys create key.json --iam-account="$SA_EMAIL" --project="$PROJECT_ID"
172
+ mfw google-chat set-key key.json --subscription "projects/${PROJECT_ID}/subscriptions/${SUBSCRIPTION}"
173
+ rm key.json
174
+ ```
175
+
176
+ The old instance's key stays valid until you delete it, and a service account holds at most 10 keys, after which `keys create` fails. List them and delete the ones no instance uses anymore:
177
+
178
+ ```bash
179
+ gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --project="$PROJECT_ID" --managed-by=user
180
+ gcloud iam service-accounts keys delete <KEY_ID> --iam-account="$SA_EMAIL" --project="$PROJECT_ID"
181
+ ```
182
+
183
+ The key the new app uses is the one with the latest `CREATED_AT`.
184
+
185
+ Start it and check it as in [step 8](#8-start-and-try-it).
186
+
144
187
  ## When the subscription disappears
145
188
 
146
189
  A subscription created before `--expiration-period=never` was in step 4 still has the default policy, and Pub/Sub deletes it after 31 days without a pull. The channel then logs `NOT_FOUND` on the subscription, while the topic, the service account and the Chat app's configuration are all still there.
@@ -171,7 +214,7 @@ gcloud pubsub subscriptions add-iam-policy-binding "$SUBSCRIPTION" \
171
214
  --role="roles/pubsub.subscriber"
172
215
  ```
173
216
 
174
- Then restart the app (`bunx mfw restart`). The messages sent while the subscription was missing are lost, though: Pub/Sub keeps messages only for a subscription that exists.
217
+ Then restart the app (`mfw restart`). The messages sent while the subscription was missing are lost, though: Pub/Sub keeps messages only for a subscription that exists.
175
218
 
176
219
  If the topic is gone too, redo steps 3 to 5 and, in step 7, paste the new topic in **Connection settings**.
177
220
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercury-fw/channel-google-chat",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,9 +34,9 @@
34
34
  "@mercury-fw/channel-types": ">=0.24.0 <1.0.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@mercury-fw/channel-types": "0.28.0",
37
+ "@mercury-fw/channel-types": "0.29.2",
38
38
  "@mercury-fw/typescript-config": "*",
39
- "@types/bun": "^1.4.0",
39
+ "@types/bun": "^1.4.2",
40
40
  "typescript": "^6.0.3"
41
41
  }
42
42
  }