activitysmith-cli 0.1.8 → 1.1.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 +366 -75
- package/package.json +3 -3
- package/src/cli.js +291 -29
package/README.md
CHANGED
|
@@ -30,11 +30,9 @@ Set `ACTIVITYSMITH_API_KEY` or pass `--api-key`.
|
|
|
30
30
|
|
|
31
31
|
For the skill scripts, you can also copy `skills/activitysmith/.env.example` to `skills/activitysmith/.env`.
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Push Notifications
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
activitysmith --help
|
|
37
|
-
```
|
|
35
|
+
Run `activitysmith --help` to inspect available commands.
|
|
38
36
|
|
|
39
37
|
### Send Push Notification
|
|
40
38
|
|
|
@@ -44,16 +42,201 @@ activitysmith push \
|
|
|
44
42
|
--message "CI pipeline failed on main branch"
|
|
45
43
|
```
|
|
46
44
|
|
|
45
|
+
### Rich Push Notifications with Media
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<img src="https://cdn.activitysmith.com/features/rich-push-notification-with-image.png" alt="Rich push notification with image" width="680" />
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
activitysmith push \
|
|
53
|
+
--title "Homepage ready" \
|
|
54
|
+
--message "Your agent finished the redesign." \
|
|
55
|
+
--media "https://cdn.example.com/output/homepage-v2.png" \
|
|
56
|
+
--redirection "https://github.com/acme/web/pull/482"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Send images, videos, or audio with your push notifications, press and hold to preview media directly from the notification, then tap through to open the linked content.
|
|
60
|
+
|
|
61
|
+
<p align="center">
|
|
62
|
+
<img src="https://cdn.activitysmith.com/features/rich-push-notification-with-audio.png" alt="Rich push notification with audio" width="680" />
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
What will work:
|
|
66
|
+
|
|
67
|
+
- direct image URL: `.jpg`, `.png`, `.gif`, etc.
|
|
68
|
+
- direct audio file URL: `.mp3`, `.m4a`, etc.
|
|
69
|
+
- direct video file URL: `.mp4`, `.mov`, etc.
|
|
70
|
+
- URL that responds with a proper media `Content-Type`, even if the path has no extension
|
|
71
|
+
|
|
72
|
+
`--media` can be combined with `--redirection`, but not with `--actions` or `--actions-file`.
|
|
73
|
+
|
|
74
|
+
### Actionable Push Notifications
|
|
75
|
+
|
|
76
|
+
<p align="center">
|
|
77
|
+
<img src="https://cdn.activitysmith.com/features/actionable-push-notifications-2.png" alt="Actionable push notification example" width="680" />
|
|
78
|
+
</p>
|
|
79
|
+
|
|
80
|
+
Actionable push notifications can open a URL on tap or trigger actions when someone long-presses the notification.
|
|
81
|
+
Webhooks are executed by the ActivitySmith backend.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
activitysmith push \
|
|
85
|
+
--title "Build Failed 🚨" \
|
|
86
|
+
--message "CI pipeline failed on main branch" \
|
|
87
|
+
--redirection "https://github.com/org/repo/actions/runs/123456789" \
|
|
88
|
+
--actions '[
|
|
89
|
+
{
|
|
90
|
+
"title": "Open Failing Run",
|
|
91
|
+
"type": "open_url",
|
|
92
|
+
"url": "https://github.com/org/repo/actions/runs/123456789"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"title": "Create Incident",
|
|
96
|
+
"type": "webhook",
|
|
97
|
+
"url": "https://hooks.example.com/incidents/create",
|
|
98
|
+
"method": "POST",
|
|
99
|
+
"body": {
|
|
100
|
+
"service": "payments-api",
|
|
101
|
+
"severity": "high",
|
|
102
|
+
"source": "activitysmith-cli"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
You can also load actions from a file:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
activitysmith push \
|
|
112
|
+
--title "Build Failed 🚨" \
|
|
113
|
+
--message "CI pipeline failed on main branch" \
|
|
114
|
+
--actions-file "./actions.json"
|
|
115
|
+
```
|
|
116
|
+
|
|
47
117
|
## Live Activities
|
|
48
118
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
119
|
+
<p align="center">
|
|
120
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Live Activities example" width="680" />
|
|
121
|
+
</p>
|
|
122
|
+
|
|
123
|
+
ActivitySmith supports two ways to drive Live Activities:
|
|
124
|
+
|
|
125
|
+
- Recommended: stream updates with `activitysmith activity stream ...`
|
|
126
|
+
- Advanced: manual lifecycle control with `activity start`, `activity update`, and `activity end`
|
|
127
|
+
|
|
128
|
+
Use stream updates when you want the easiest, stateless flow. You do not need to
|
|
129
|
+
store `activity_id` or manage lifecycle state yourself. Send the latest state
|
|
130
|
+
for a stable `stream_key` and ActivitySmith will start or update the Live
|
|
131
|
+
Activity for you. When the tracked process is over, call `activity end-stream`.
|
|
132
|
+
|
|
133
|
+
Use the manual lifecycle commands when you need direct control over a specific
|
|
134
|
+
Live Activity instance.
|
|
135
|
+
|
|
136
|
+
Live Activity UI types:
|
|
137
|
+
|
|
138
|
+
- `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag
|
|
139
|
+
- `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines
|
|
140
|
+
- `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage
|
|
141
|
+
|
|
142
|
+
### Recommended: Stream updates
|
|
143
|
+
|
|
144
|
+
Use a stable `stream_key` to identify the system or workflow you are tracking,
|
|
145
|
+
such as a server, deployment, build pipeline, cron job, or charging session.
|
|
146
|
+
This is especially useful for cron jobs and other scheduled tasks where you do
|
|
147
|
+
not want to store `activity_id` between runs.
|
|
148
|
+
|
|
149
|
+
#### Metrics
|
|
150
|
+
|
|
151
|
+
<p align="center">
|
|
152
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-start.png" alt="Metrics stream example" width="680" />
|
|
153
|
+
</p>
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
activitysmith activity stream prod-web-1 \
|
|
157
|
+
--content-state '{
|
|
158
|
+
"title": "Server Health",
|
|
159
|
+
"subtitle": "prod-web-1",
|
|
160
|
+
"type": "metrics",
|
|
161
|
+
"metrics": [
|
|
162
|
+
{ "label": "CPU", "value": 9, "unit": "%" },
|
|
163
|
+
{ "label": "MEM", "value": 45, "unit": "%" }
|
|
164
|
+
]
|
|
165
|
+
}'
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Segmented progress
|
|
169
|
+
|
|
170
|
+
<p align="center">
|
|
171
|
+
<img src="https://cdn.activitysmith.com/features/update-live-activity.png" alt="Segmented progress stream example" width="680" />
|
|
172
|
+
</p>
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
activitysmith activity stream nightly-backup \
|
|
176
|
+
--content-state '{
|
|
177
|
+
"title": "Nightly Backup",
|
|
178
|
+
"subtitle": "upload archive",
|
|
179
|
+
"type": "segmented_progress",
|
|
180
|
+
"numberOfSteps": 3,
|
|
181
|
+
"currentStep": 2
|
|
182
|
+
}'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Progress
|
|
186
|
+
|
|
187
|
+
<p align="center">
|
|
188
|
+
<img src="https://cdn.activitysmith.com/features/progress-live-activity.png" alt="Progress stream example" width="680" />
|
|
189
|
+
</p>
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
activitysmith activity stream search-reindex \
|
|
193
|
+
--content-state '{
|
|
194
|
+
"title": "Search Reindex",
|
|
195
|
+
"subtitle": "catalog-v2",
|
|
196
|
+
"type": "progress",
|
|
197
|
+
"percentage": 42
|
|
198
|
+
}'
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Run `activitysmith activity stream <stream-key> ...` again with the same
|
|
202
|
+
`stream_key` whenever the state changes.
|
|
203
|
+
|
|
204
|
+
#### End a stream
|
|
205
|
+
|
|
206
|
+
Use this when the tracked process is finished and you no longer want the Live
|
|
207
|
+
Activity on devices. `content_state` is optional here; include it if you want
|
|
208
|
+
to end the stream with a final state.
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
activitysmith activity end-stream prod-web-1 \
|
|
212
|
+
--content-state '{
|
|
213
|
+
"title": "Server Health",
|
|
214
|
+
"subtitle": "prod-web-1",
|
|
215
|
+
"type": "metrics",
|
|
216
|
+
"metrics": [
|
|
217
|
+
{ "label": "CPU", "value": 7, "unit": "%" },
|
|
218
|
+
{ "label": "MEM", "value": 38, "unit": "%" }
|
|
219
|
+
]
|
|
220
|
+
}'
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
If you later send another `activity stream` request with the same `stream_key`,
|
|
224
|
+
ActivitySmith starts a new Live Activity for that stream again.
|
|
225
|
+
|
|
226
|
+
Stream responses include an `operation` field:
|
|
227
|
+
|
|
228
|
+
- `started`: ActivitySmith started a new Live Activity for this `stream_key`
|
|
229
|
+
- `updated`: ActivitySmith updated the current Live Activity
|
|
230
|
+
- `rotated`: ActivitySmith ended the previous Live Activity and started a new one
|
|
231
|
+
- `noop`: the incoming state matched the current state, so no update was sent
|
|
232
|
+
- `paused`: the stream is paused, so no Live Activity was started or updated
|
|
233
|
+
- `ended`: returned by `activity end-stream` after the stream is ended
|
|
52
234
|
|
|
53
|
-
|
|
54
|
-
- `progress`: best for jobs tracked as a percentage or numeric range
|
|
235
|
+
### Advanced: Manual lifecycle control
|
|
55
236
|
|
|
56
|
-
|
|
237
|
+
Use these commands when you want to manage the Live Activity lifecycle yourself.
|
|
238
|
+
|
|
239
|
+
#### Shared flow
|
|
57
240
|
|
|
58
241
|
1. Run `activitysmith activity start ...`.
|
|
59
242
|
2. Save the returned `activity_id`.
|
|
@@ -63,157 +246,249 @@ changes, then end it when the work is done.
|
|
|
63
246
|
You can use `--content-state <json>` for the examples below, or build the same
|
|
64
247
|
payload with flags as documented in `Content State Options`.
|
|
65
248
|
|
|
66
|
-
###
|
|
249
|
+
### Metrics Type
|
|
67
250
|
|
|
68
|
-
Use `
|
|
69
|
-
|
|
70
|
-
checklists where "step 2 of 3" is more useful than "67%".
|
|
71
|
-
`numberOfSteps` is dynamic, so you can increase or decrease it later if the
|
|
72
|
-
workflow changes.
|
|
251
|
+
Use `metrics` when you want to keep a small set of live stats visible, such as
|
|
252
|
+
server health, queue pressure, or database load.
|
|
73
253
|
|
|
74
254
|
#### Start
|
|
75
255
|
|
|
76
256
|
<p align="center">
|
|
77
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
257
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-start.png" alt="Metrics start example" width="680" />
|
|
78
258
|
</p>
|
|
79
259
|
|
|
80
260
|
```bash
|
|
81
261
|
activitysmith activity start \
|
|
82
|
-
--content-state '{
|
|
83
|
-
|
|
262
|
+
--content-state '{
|
|
263
|
+
"title": "Server Health",
|
|
264
|
+
"subtitle": "prod-web-1",
|
|
265
|
+
"type": "metrics",
|
|
266
|
+
"metrics": [
|
|
267
|
+
{ "label": "CPU", "value": 9, "unit": "%" },
|
|
268
|
+
{ "label": "MEM", "value": 45, "unit": "%" }
|
|
269
|
+
]
|
|
270
|
+
}'
|
|
84
271
|
```
|
|
85
272
|
|
|
86
273
|
#### Update
|
|
87
274
|
|
|
88
275
|
<p align="center">
|
|
89
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
276
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-update.png" alt="Metrics update example" width="680" />
|
|
90
277
|
</p>
|
|
91
278
|
|
|
92
279
|
```bash
|
|
93
280
|
activitysmith activity update \
|
|
94
281
|
--activity-id "<activityId>" \
|
|
95
|
-
--content-state '{
|
|
282
|
+
--content-state '{
|
|
283
|
+
"title": "Server Health",
|
|
284
|
+
"subtitle": "prod-web-1",
|
|
285
|
+
"type": "metrics",
|
|
286
|
+
"metrics": [
|
|
287
|
+
{ "label": "CPU", "value": 76, "unit": "%" },
|
|
288
|
+
{ "label": "MEM", "value": 52, "unit": "%" }
|
|
289
|
+
]
|
|
290
|
+
}'
|
|
96
291
|
```
|
|
97
292
|
|
|
98
293
|
#### End
|
|
99
294
|
|
|
100
295
|
<p align="center">
|
|
101
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
296
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-end.png" alt="Metrics end example" width="680" />
|
|
102
297
|
</p>
|
|
103
298
|
|
|
104
299
|
```bash
|
|
105
300
|
activitysmith activity end \
|
|
106
301
|
--activity-id "<activityId>" \
|
|
107
|
-
--content-state '{
|
|
302
|
+
--content-state '{
|
|
303
|
+
"title": "Server Health",
|
|
304
|
+
"subtitle": "prod-web-1",
|
|
305
|
+
"type": "metrics",
|
|
306
|
+
"metrics": [
|
|
307
|
+
{ "label": "CPU", "value": 7, "unit": "%" },
|
|
308
|
+
{ "label": "MEM", "value": 38, "unit": "%" }
|
|
309
|
+
],
|
|
310
|
+
"autoDismissMinutes": 2
|
|
311
|
+
}'
|
|
108
312
|
```
|
|
109
313
|
|
|
110
|
-
### Progress Type
|
|
314
|
+
### Segmented Progress Type
|
|
111
315
|
|
|
112
|
-
Use `
|
|
113
|
-
|
|
114
|
-
|
|
316
|
+
Use `segmented_progress` when progress is easier to follow as steps instead of a
|
|
317
|
+
raw percentage. It fits jobs like deployments, backups, ETL pipelines, and
|
|
318
|
+
checklists where "step 2 of 3" is more useful than "67%". `numberOfSteps` is
|
|
319
|
+
dynamic, so you can increase or decrease it later if the workflow changes.
|
|
115
320
|
|
|
116
321
|
#### Start
|
|
117
322
|
|
|
118
323
|
<p align="center">
|
|
119
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
324
|
+
<img src="https://cdn.activitysmith.com/features/start-live-activity.png" alt="Segmented progress start example" width="680" />
|
|
120
325
|
</p>
|
|
121
326
|
|
|
122
327
|
```bash
|
|
123
328
|
activitysmith activity start \
|
|
124
|
-
--content-state '{
|
|
329
|
+
--content-state '{
|
|
330
|
+
"title": "Nightly database backup",
|
|
331
|
+
"subtitle": "create snapshot",
|
|
332
|
+
"numberOfSteps": 3,
|
|
333
|
+
"currentStep": 1,
|
|
334
|
+
"type": "segmented_progress",
|
|
335
|
+
"color": "yellow"
|
|
336
|
+
}'
|
|
125
337
|
```
|
|
126
338
|
|
|
127
339
|
#### Update
|
|
128
340
|
|
|
129
341
|
<p align="center">
|
|
130
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
342
|
+
<img src="https://cdn.activitysmith.com/features/update-live-activity.png" alt="Segmented progress update example" width="680" />
|
|
131
343
|
</p>
|
|
132
344
|
|
|
133
345
|
```bash
|
|
134
346
|
activitysmith activity update \
|
|
135
347
|
--activity-id "<activityId>" \
|
|
136
|
-
--content-state '{
|
|
348
|
+
--content-state '{
|
|
349
|
+
"title": "Nightly database backup",
|
|
350
|
+
"subtitle": "upload archive",
|
|
351
|
+
"numberOfSteps": 3,
|
|
352
|
+
"currentStep": 2
|
|
353
|
+
}'
|
|
137
354
|
```
|
|
138
355
|
|
|
139
356
|
#### End
|
|
140
357
|
|
|
141
358
|
<p align="center">
|
|
142
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
359
|
+
<img src="https://cdn.activitysmith.com/features/end-live-activity.png" alt="Segmented progress end example" width="680" />
|
|
143
360
|
</p>
|
|
144
361
|
|
|
145
362
|
```bash
|
|
146
363
|
activitysmith activity end \
|
|
147
364
|
--activity-id "<activityId>" \
|
|
148
|
-
--content-state '{
|
|
365
|
+
--content-state '{
|
|
366
|
+
"title": "Nightly database backup",
|
|
367
|
+
"subtitle": "verify restore",
|
|
368
|
+
"numberOfSteps": 3,
|
|
369
|
+
"currentStep": 3,
|
|
370
|
+
"autoDismissMinutes": 2
|
|
371
|
+
}'
|
|
149
372
|
```
|
|
150
373
|
|
|
151
|
-
###
|
|
374
|
+
### Progress Type
|
|
152
375
|
|
|
153
|
-
|
|
376
|
+
Use `progress` when the state is naturally continuous. It fits charging,
|
|
377
|
+
downloads, sync jobs, uploads, timers, and any flow where a percentage or
|
|
378
|
+
numeric range is the clearest signal.
|
|
379
|
+
|
|
380
|
+
#### Start
|
|
381
|
+
|
|
382
|
+
<p align="center">
|
|
383
|
+
<img src="https://cdn.activitysmith.com/features/progress-live-activity-start.png" alt="Progress start example" width="680" />
|
|
384
|
+
</p>
|
|
154
385
|
|
|
155
386
|
```bash
|
|
156
|
-
activitysmith
|
|
157
|
-
--
|
|
158
|
-
|
|
159
|
-
|
|
387
|
+
activitysmith activity start \
|
|
388
|
+
--content-state '{
|
|
389
|
+
"title": "EV Charging",
|
|
390
|
+
"subtitle": "Added 30 mi range",
|
|
391
|
+
"type": "progress",
|
|
392
|
+
"percentage": 15
|
|
393
|
+
}'
|
|
160
394
|
```
|
|
161
395
|
|
|
162
|
-
|
|
396
|
+
#### Update
|
|
163
397
|
|
|
164
398
|
<p align="center">
|
|
165
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
399
|
+
<img src="https://cdn.activitysmith.com/features/progress-live-activity-update.png" alt="Progress update example" width="680" />
|
|
166
400
|
</p>
|
|
167
401
|
|
|
168
402
|
```bash
|
|
169
|
-
activitysmith
|
|
170
|
-
--
|
|
171
|
-
--
|
|
172
|
-
|
|
173
|
-
|
|
403
|
+
activitysmith activity update \
|
|
404
|
+
--activity-id "<activityId>" \
|
|
405
|
+
--content-state '{
|
|
406
|
+
"title": "EV Charging",
|
|
407
|
+
"subtitle": "Added 120 mi range",
|
|
408
|
+
"percentage": 60
|
|
409
|
+
}'
|
|
174
410
|
```
|
|
175
411
|
|
|
176
|
-
|
|
412
|
+
#### End
|
|
177
413
|
|
|
178
414
|
<p align="center">
|
|
179
|
-
<img src="https://cdn.activitysmith.com/features/
|
|
415
|
+
<img src="https://cdn.activitysmith.com/features/progress-live-activity-end.png" alt="Progress end example" width="680" />
|
|
180
416
|
</p>
|
|
181
417
|
|
|
182
|
-
|
|
418
|
+
```bash
|
|
419
|
+
activitysmith activity end \
|
|
420
|
+
--activity-id "<activityId>" \
|
|
421
|
+
--content-state '{
|
|
422
|
+
"title": "EV Charging",
|
|
423
|
+
"subtitle": "Added 200 mi range",
|
|
424
|
+
"percentage": 100,
|
|
425
|
+
"autoDismissMinutes": 2
|
|
426
|
+
}'
|
|
427
|
+
```
|
|
183
428
|
|
|
184
|
-
|
|
185
|
-
- direct audio file URL: `.mp3`, `.m4a`, etc.
|
|
186
|
-
- direct video file URL: `.mp4`, `.mov`, etc.
|
|
187
|
-
- URL that responds with a proper media `Content-Type`, even if the path has no extension
|
|
429
|
+
### Live Activity Action
|
|
188
430
|
|
|
189
|
-
|
|
431
|
+
Just like Actionable Push Notifications, Live Activities can have a button that opens a URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend.
|
|
190
432
|
|
|
191
|
-
|
|
433
|
+
<p align="center">
|
|
434
|
+
<img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity with action" width="680" />
|
|
435
|
+
</p>
|
|
192
436
|
|
|
193
|
-
|
|
194
|
-
Webhooks are executed by ActivitySmith backend.
|
|
437
|
+
#### Open URL action
|
|
195
438
|
|
|
196
439
|
```bash
|
|
197
|
-
activitysmith
|
|
198
|
-
--
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
440
|
+
activitysmith activity start \
|
|
441
|
+
--content-state '{
|
|
442
|
+
"title": "Server Health",
|
|
443
|
+
"subtitle": "prod-web-1",
|
|
444
|
+
"type": "metrics",
|
|
445
|
+
"metrics": [
|
|
446
|
+
{ "label": "CPU", "value": 76, "unit": "%" },
|
|
447
|
+
{ "label": "MEM", "value": 52, "unit": "%" }
|
|
448
|
+
]
|
|
449
|
+
}' \
|
|
450
|
+
--action '{
|
|
451
|
+
"title": "Open Dashboard",
|
|
452
|
+
"type": "open_url",
|
|
453
|
+
"url": "https://ops.example.com/servers/prod-web-1"
|
|
454
|
+
}'
|
|
202
455
|
```
|
|
203
456
|
|
|
204
|
-
|
|
457
|
+
#### Webhook action
|
|
205
458
|
|
|
206
459
|
```bash
|
|
207
|
-
activitysmith
|
|
208
|
-
--
|
|
209
|
-
--
|
|
210
|
-
|
|
460
|
+
activitysmith activity update \
|
|
461
|
+
--activity-id "<activityId>" \
|
|
462
|
+
--content-state '{
|
|
463
|
+
"title": "Server Health",
|
|
464
|
+
"subtitle": "prod-web-1",
|
|
465
|
+
"type": "metrics",
|
|
466
|
+
"metrics": [
|
|
467
|
+
{ "label": "CPU", "value": 91, "unit": "%" },
|
|
468
|
+
{ "label": "MEM", "value": 57, "unit": "%" }
|
|
469
|
+
]
|
|
470
|
+
}' \
|
|
471
|
+
--action '{
|
|
472
|
+
"title": "Restart Service",
|
|
473
|
+
"type": "webhook",
|
|
474
|
+
"url": "https://ops.example.com/hooks/servers/prod-web-1/restart",
|
|
475
|
+
"method": "POST",
|
|
476
|
+
"body": {
|
|
477
|
+
"server_id": "prod-web-1",
|
|
478
|
+
"requested_by": "activitysmith-cli"
|
|
479
|
+
}
|
|
480
|
+
}'
|
|
211
481
|
```
|
|
212
482
|
|
|
213
|
-
|
|
483
|
+
## Channels
|
|
484
|
+
|
|
485
|
+
Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
|
|
214
486
|
|
|
215
487
|
```bash
|
|
216
|
-
activitysmith push
|
|
488
|
+
activitysmith push \
|
|
489
|
+
--title "Build Failed 🚨" \
|
|
490
|
+
--message "CI pipeline failed on main branch" \
|
|
491
|
+
--channels "devs,ops"
|
|
217
492
|
```
|
|
218
493
|
|
|
219
494
|
## Aliases
|
|
@@ -225,12 +500,17 @@ The CLI installs two bin names:
|
|
|
225
500
|
|
|
226
501
|
## Content State Options
|
|
227
502
|
|
|
228
|
-
For `activity start|update|end`, you can pass content state via JSON:
|
|
503
|
+
For `activity stream|start|update|end|end-stream`, you can pass content state via JSON:
|
|
229
504
|
|
|
230
505
|
- `--content-state <json>`
|
|
231
506
|
- `--content-state-file <path>`
|
|
232
507
|
|
|
233
|
-
|
|
508
|
+
For `metrics`, you can also pass the metrics array directly:
|
|
509
|
+
|
|
510
|
+
- `--metrics <json-array>`
|
|
511
|
+
- `--metrics-file <path>`
|
|
512
|
+
|
|
513
|
+
Or use flags to build the rest of the payload:
|
|
234
514
|
|
|
235
515
|
- `--title <title>`
|
|
236
516
|
- `--subtitle <subtitle>`
|
|
@@ -244,16 +524,27 @@ Or use flags to build the payload:
|
|
|
244
524
|
- `--step-color <color>`
|
|
245
525
|
- `--auto-dismiss-minutes <number>`
|
|
246
526
|
|
|
527
|
+
Live Activity action options:
|
|
528
|
+
|
|
529
|
+
- `--action <json>`
|
|
530
|
+
- `--action-file <path>`
|
|
531
|
+
|
|
247
532
|
Targeting options:
|
|
248
533
|
|
|
249
|
-
- `--channels <comma-separated-slugs>` (for `push` and `activity start`)
|
|
534
|
+
- `--channels <comma-separated-slugs>` (for `push`, `activity stream`, and `activity start`)
|
|
250
535
|
|
|
251
536
|
Required fields:
|
|
252
537
|
|
|
253
|
-
- `activity
|
|
254
|
-
- `activity
|
|
255
|
-
- `activity
|
|
538
|
+
- `activity stream`: `--title`, `--type`, plus `--metrics`, `--number-of-steps` and `--current-step`, `--percentage`, or `--value` with `--upper-limit`
|
|
539
|
+
- `activity start`: `--title`, `--type`, plus `--metrics`, `--number-of-steps` and `--current-step`, `--percentage`, or `--value` with `--upper-limit`
|
|
540
|
+
- `activity update`: `--title`, plus `--metrics`, `--current-step`, `--percentage`, or `--value` with `--upper-limit`
|
|
541
|
+
- `activity end`: `--title`, plus `--metrics`, `--current-step`, `--percentage`, or `--value` with `--upper-limit`
|
|
542
|
+
- `activity end-stream`: no content state is required, but if you provide one it follows the same rules as `activity end`
|
|
256
543
|
|
|
257
544
|
## Output
|
|
258
545
|
|
|
259
546
|
Use `--json` for machine-readable output.
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
activitysmith push --title "Hello" --json
|
|
550
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "activitysmith-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Command-line interface for ActivitySmith. Send push notifications
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Command-line interface for ActivitySmith. Send push notifications and manage Live Activities from your terminal.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"activitysmith",
|
|
7
7
|
"live-activities",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lint": "node --check src/cli.js"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"activitysmith": "^
|
|
43
|
+
"activitysmith": "^1.1.0",
|
|
44
44
|
"commander": "^12.1.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/cli.js
CHANGED
|
@@ -77,6 +77,8 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
|
|
|
77
77
|
command
|
|
78
78
|
.option("--content-state <json>", "Content state as JSON string")
|
|
79
79
|
.option("--content-state-file <path>", "Content state JSON file path")
|
|
80
|
+
.option("--metrics <json>", "Content state metrics as JSON array")
|
|
81
|
+
.option("--metrics-file <path>", "Content state metrics JSON file path")
|
|
80
82
|
.option("--title <title>", "Content state title")
|
|
81
83
|
.option("--subtitle <subtitle>", "Content state subtitle")
|
|
82
84
|
.option("--type <type>", "Content state type")
|
|
@@ -119,6 +121,11 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
|
|
|
119
121
|
return command;
|
|
120
122
|
};
|
|
121
123
|
|
|
124
|
+
const addLiveActivityActionOptions = (command) =>
|
|
125
|
+
command
|
|
126
|
+
.option("--action <json>", "Live Activity action as JSON object")
|
|
127
|
+
.option("--action-file <path>", "Live Activity action JSON file path");
|
|
128
|
+
|
|
122
129
|
const getApiKey = (options) =>
|
|
123
130
|
options.apiKey || process.env.ACTIVITYSMITH_API_KEY;
|
|
124
131
|
|
|
@@ -216,10 +223,11 @@ const validateContentState = (contentState, mode) => {
|
|
|
216
223
|
if (
|
|
217
224
|
normalizedType !== undefined &&
|
|
218
225
|
normalizedType !== "segmented_progress" &&
|
|
219
|
-
normalizedType !== "progress"
|
|
226
|
+
normalizedType !== "progress" &&
|
|
227
|
+
normalizedType !== "metrics"
|
|
220
228
|
) {
|
|
221
229
|
throw new Error(
|
|
222
|
-
"contentState.type must be one of: segmented_progress, progress"
|
|
230
|
+
"contentState.type must be one of: segmented_progress, progress, metrics"
|
|
223
231
|
);
|
|
224
232
|
}
|
|
225
233
|
|
|
@@ -229,6 +237,7 @@ const validateContentState = (contentState, mode) => {
|
|
|
229
237
|
const hasValue = hasOwn(contentState, "value");
|
|
230
238
|
const hasUpperLimit = hasOwn(contentState, "upperLimit");
|
|
231
239
|
const hasStepColor = hasOwn(contentState, "stepColor");
|
|
240
|
+
const hasMetrics = hasOwn(contentState, "metrics");
|
|
232
241
|
|
|
233
242
|
if (hasValue !== hasUpperLimit) {
|
|
234
243
|
throw new Error(
|
|
@@ -264,11 +273,36 @@ const validateContentState = (contentState, mode) => {
|
|
|
264
273
|
);
|
|
265
274
|
}
|
|
266
275
|
|
|
276
|
+
if (hasMetrics && (hasSegmentedFields || hasProgressFields)) {
|
|
277
|
+
throw new Error(
|
|
278
|
+
"Do not mix metrics fields with segmented_progress or progress fields in the same contentState"
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (hasMetrics) {
|
|
283
|
+
if (!Array.isArray(contentState.metrics) || contentState.metrics.length === 0) {
|
|
284
|
+
throw new Error("contentState.metrics must be a non-empty array");
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
contentState.metrics.forEach((metric, index) => {
|
|
288
|
+
assertPlainObject(metric, `contentState.metrics[${index}]`);
|
|
289
|
+
if (!isNonEmptyString(metric.label)) {
|
|
290
|
+
throw new Error(`contentState.metrics[${index}].label is required`);
|
|
291
|
+
}
|
|
292
|
+
if (!Number.isFinite(metric.value)) {
|
|
293
|
+
throw new Error(`contentState.metrics[${index}].value must be a number`);
|
|
294
|
+
}
|
|
295
|
+
if (metric.unit !== undefined && typeof metric.unit !== "string") {
|
|
296
|
+
throw new Error(`contentState.metrics[${index}].unit must be a string`);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
267
301
|
const effectiveType = normalizedType;
|
|
268
302
|
|
|
269
|
-
if (mode === "start") {
|
|
303
|
+
if (mode === "start" || mode === "stream") {
|
|
270
304
|
if (!effectiveType) {
|
|
271
|
-
throw new Error(
|
|
305
|
+
throw new Error(`contentState.type is required for activity ${mode}`);
|
|
272
306
|
}
|
|
273
307
|
|
|
274
308
|
if (effectiveType === "segmented_progress") {
|
|
@@ -280,9 +314,16 @@ const validateContentState = (contentState, mode) => {
|
|
|
280
314
|
return;
|
|
281
315
|
}
|
|
282
316
|
|
|
317
|
+
if (effectiveType === "metrics") {
|
|
318
|
+
if (!hasMetrics) {
|
|
319
|
+
throw new Error(`metrics ${mode} requires contentState.metrics`);
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
283
324
|
if (!hasPercentage && !hasValue) {
|
|
284
325
|
throw new Error(
|
|
285
|
-
|
|
326
|
+
`progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
|
|
286
327
|
);
|
|
287
328
|
}
|
|
288
329
|
return;
|
|
@@ -306,12 +347,23 @@ const validateContentState = (contentState, mode) => {
|
|
|
306
347
|
return;
|
|
307
348
|
}
|
|
308
349
|
|
|
309
|
-
if (
|
|
350
|
+
if (effectiveType === "metrics") {
|
|
351
|
+
if (!hasMetrics) {
|
|
352
|
+
throw new Error(`metrics ${mode} requires contentState.metrics`);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (!hasSegmentedFields && !hasProgressFields && !hasMetrics) {
|
|
310
358
|
throw new Error(
|
|
311
|
-
`contentState for activity ${mode} must include
|
|
359
|
+
`contentState for activity ${mode} must include metrics, segmented_progress fields, or progress fields`
|
|
312
360
|
);
|
|
313
361
|
}
|
|
314
362
|
|
|
363
|
+
if (hasMetrics) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
315
367
|
if (hasSegmentedFields && !hasCurrentStep) {
|
|
316
368
|
throw new Error(
|
|
317
369
|
`segmented_progress ${mode} requires contentState.currentStep`
|
|
@@ -325,8 +377,7 @@ const validateContentState = (contentState, mode) => {
|
|
|
325
377
|
}
|
|
326
378
|
};
|
|
327
379
|
|
|
328
|
-
const
|
|
329
|
-
const label = `actions[${index}]`;
|
|
380
|
+
const parseAction = (value, label) => {
|
|
330
381
|
assertPlainObject(value, label);
|
|
331
382
|
|
|
332
383
|
if (typeof value.title !== "string" || value.title.trim().length === 0) {
|
|
@@ -371,6 +422,8 @@ const parsePushAction = (value, index) => {
|
|
|
371
422
|
return action;
|
|
372
423
|
};
|
|
373
424
|
|
|
425
|
+
const parsePushAction = (value, index) => parseAction(value, `actions[${index}]`);
|
|
426
|
+
|
|
374
427
|
const loadPushActions = async (options) => {
|
|
375
428
|
if (options.actions && options.actionsFile) {
|
|
376
429
|
throw new Error("Provide either --actions or --actions-file, not both.");
|
|
@@ -400,6 +453,27 @@ const loadPushActions = async (options) => {
|
|
|
400
453
|
return actions.map(parsePushAction);
|
|
401
454
|
};
|
|
402
455
|
|
|
456
|
+
const loadLiveActivityAction = async (options) => {
|
|
457
|
+
if (options.action && options.actionFile) {
|
|
458
|
+
throw new Error("Provide either --action or --action-file, not both.");
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
let action;
|
|
462
|
+
if (options.actionFile) {
|
|
463
|
+
action = await readJsonFile(options.actionFile, "action-file");
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (options.action) {
|
|
467
|
+
action = parseJsonString(options.action, "action");
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (action === undefined) {
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return parseAction(action, "action");
|
|
475
|
+
};
|
|
476
|
+
|
|
403
477
|
const validatePushMediaOptions = ({ media, actions }) => {
|
|
404
478
|
if (media === undefined || actions === undefined) {
|
|
405
479
|
return;
|
|
@@ -460,6 +534,22 @@ const buildContentStateFromOptions = (options) => {
|
|
|
460
534
|
return contentState;
|
|
461
535
|
};
|
|
462
536
|
|
|
537
|
+
const loadMetrics = async (options) => {
|
|
538
|
+
if (options.metrics && options.metricsFile) {
|
|
539
|
+
throw new Error("Provide either --metrics or --metrics-file, not both.");
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (options.metricsFile) {
|
|
543
|
+
return readJsonArrayFile(options.metricsFile, "metrics-file");
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (options.metrics) {
|
|
547
|
+
return parseJsonArrayString(options.metrics, "metrics");
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return undefined;
|
|
551
|
+
};
|
|
552
|
+
|
|
463
553
|
const toApiContentState = (contentState) => {
|
|
464
554
|
const keyMap = {
|
|
465
555
|
numberOfSteps: "number_of_steps",
|
|
@@ -483,9 +573,17 @@ const toApiContentState = (contentState) => {
|
|
|
483
573
|
return mapped;
|
|
484
574
|
};
|
|
485
575
|
|
|
486
|
-
const toApiLiveActivityStartRequest = (contentState) =>
|
|
487
|
-
|
|
488
|
-
|
|
576
|
+
const toApiLiveActivityStartRequest = (contentState, action) => {
|
|
577
|
+
const request = {
|
|
578
|
+
content_state: toApiContentState(contentState),
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
if (action !== undefined) {
|
|
582
|
+
request.action = action;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return request;
|
|
586
|
+
};
|
|
489
587
|
|
|
490
588
|
const withTargetChannels = (request, channels) => {
|
|
491
589
|
if (!channels || channels.length === 0) {
|
|
@@ -500,15 +598,57 @@ const withTargetChannels = (request, channels) => {
|
|
|
500
598
|
};
|
|
501
599
|
};
|
|
502
600
|
|
|
503
|
-
const toApiLiveActivityUpdateRequest = (activityId, contentState) =>
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
601
|
+
const toApiLiveActivityUpdateRequest = (activityId, contentState, action) => {
|
|
602
|
+
const request = {
|
|
603
|
+
activity_id: activityId,
|
|
604
|
+
content_state: toApiContentState(contentState),
|
|
605
|
+
};
|
|
507
606
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
607
|
+
if (action !== undefined) {
|
|
608
|
+
request.action = action;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return request;
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
const toApiLiveActivityEndRequest = (activityId, contentState, action) => {
|
|
615
|
+
const request = {
|
|
616
|
+
activity_id: activityId,
|
|
617
|
+
content_state: toApiContentState(contentState),
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
if (action !== undefined) {
|
|
621
|
+
request.action = action;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return request;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
const toApiLiveActivityStreamRequest = (contentState, action) => {
|
|
628
|
+
const request = {
|
|
629
|
+
content_state: toApiContentState(contentState),
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
if (action !== undefined) {
|
|
633
|
+
request.action = action;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return request;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
const toApiLiveActivityStreamDeleteRequest = (contentState, action) => {
|
|
640
|
+
const request = {};
|
|
641
|
+
|
|
642
|
+
if (contentState !== undefined) {
|
|
643
|
+
request.content_state = toApiContentState(contentState);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (action !== undefined) {
|
|
647
|
+
request.action = action;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return request;
|
|
651
|
+
};
|
|
512
652
|
|
|
513
653
|
const loadContentState = async (options, mode) => {
|
|
514
654
|
let contentState = {};
|
|
@@ -532,6 +672,11 @@ const loadContentState = async (options, mode) => {
|
|
|
532
672
|
const fromFlags = buildContentStateFromOptions(options);
|
|
533
673
|
contentState = { ...contentState, ...fromFlags };
|
|
534
674
|
|
|
675
|
+
const metrics = await loadMetrics(options);
|
|
676
|
+
if (metrics !== undefined) {
|
|
677
|
+
contentState.metrics = metrics;
|
|
678
|
+
}
|
|
679
|
+
|
|
535
680
|
if (Object.keys(contentState).length === 0) {
|
|
536
681
|
throw new Error(
|
|
537
682
|
"contentState is required. Provide --content-state, --content-state-file, or field flags."
|
|
@@ -543,6 +688,41 @@ const loadContentState = async (options, mode) => {
|
|
|
543
688
|
return contentState;
|
|
544
689
|
};
|
|
545
690
|
|
|
691
|
+
const loadOptionalContentState = async (options, mode) => {
|
|
692
|
+
let contentState = {};
|
|
693
|
+
|
|
694
|
+
if (options.contentStateFile) {
|
|
695
|
+
const fromFile = await readJsonFile(
|
|
696
|
+
options.contentStateFile,
|
|
697
|
+
"content-state-file"
|
|
698
|
+
);
|
|
699
|
+
contentState = { ...contentState, ...fromFile };
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (options.contentState) {
|
|
703
|
+
const fromString = parseJsonString(
|
|
704
|
+
options.contentState,
|
|
705
|
+
"content-state"
|
|
706
|
+
);
|
|
707
|
+
contentState = { ...contentState, ...fromString };
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const fromFlags = buildContentStateFromOptions(options);
|
|
711
|
+
contentState = { ...contentState, ...fromFlags };
|
|
712
|
+
|
|
713
|
+
const metrics = await loadMetrics(options);
|
|
714
|
+
if (metrics !== undefined) {
|
|
715
|
+
contentState.metrics = metrics;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (Object.keys(contentState).length === 0) {
|
|
719
|
+
return undefined;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
validateContentState(contentState, mode);
|
|
723
|
+
return contentState;
|
|
724
|
+
};
|
|
725
|
+
|
|
546
726
|
const formatError = (error) => {
|
|
547
727
|
if (!error) {
|
|
548
728
|
return "Unknown error";
|
|
@@ -727,7 +907,48 @@ const activityCommand = program
|
|
|
727
907
|
.command("activity")
|
|
728
908
|
.description("Manage Live Activities");
|
|
729
909
|
|
|
730
|
-
addContentStateOptions(
|
|
910
|
+
addLiveActivityActionOptions(addContentStateOptions(
|
|
911
|
+
activityCommand
|
|
912
|
+
.command("stream")
|
|
913
|
+
.description("Send a stateless Live Activity stream update")
|
|
914
|
+
.argument("<stream-key>", "Stable stream key")
|
|
915
|
+
.option(
|
|
916
|
+
"--channels <channels>",
|
|
917
|
+
"Comma-separated channel slugs (optional)",
|
|
918
|
+
parseChannelsOption
|
|
919
|
+
)
|
|
920
|
+
.action(async (streamKey, options) => {
|
|
921
|
+
const globalOptions = program.opts();
|
|
922
|
+
|
|
923
|
+
try {
|
|
924
|
+
const apiKey = requireApiKey(globalOptions);
|
|
925
|
+
const client = createClient(apiKey);
|
|
926
|
+
const contentState = await loadContentState(options, "stream");
|
|
927
|
+
const action = await loadLiveActivityAction(options);
|
|
928
|
+
|
|
929
|
+
const response = await client.liveActivities.stream(
|
|
930
|
+
streamKey,
|
|
931
|
+
withTargetChannels(
|
|
932
|
+
toApiLiveActivityStreamRequest(contentState, action),
|
|
933
|
+
options.channels
|
|
934
|
+
)
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
const activityId = response?.activityId ?? response?.activity_id;
|
|
938
|
+
const operation = response?.operation;
|
|
939
|
+
outputResult(response, globalOptions, [
|
|
940
|
+
"Live Activity stream reconciled.",
|
|
941
|
+
streamKey ? `Stream key: ${streamKey}` : null,
|
|
942
|
+
operation ? `Operation: ${operation}` : null,
|
|
943
|
+
activityId ? `Activity ID: ${activityId}` : null,
|
|
944
|
+
]);
|
|
945
|
+
} catch (error) {
|
|
946
|
+
await handleError(error, globalOptions);
|
|
947
|
+
}
|
|
948
|
+
})
|
|
949
|
+
));
|
|
950
|
+
|
|
951
|
+
addLiveActivityActionOptions(addContentStateOptions(
|
|
731
952
|
activityCommand
|
|
732
953
|
.command("start")
|
|
733
954
|
.description("Start a Live Activity")
|
|
@@ -743,10 +964,11 @@ addContentStateOptions(
|
|
|
743
964
|
const apiKey = requireApiKey(globalOptions);
|
|
744
965
|
const client = createClient(apiKey);
|
|
745
966
|
const contentState = await loadContentState(options, "start");
|
|
967
|
+
const action = await loadLiveActivityAction(options);
|
|
746
968
|
|
|
747
969
|
const response = await client.liveActivities.startLiveActivity({
|
|
748
970
|
liveActivityStartRequest: withTargetChannels(
|
|
749
|
-
toApiLiveActivityStartRequest(contentState),
|
|
971
|
+
toApiLiveActivityStartRequest(contentState, action),
|
|
750
972
|
options.channels
|
|
751
973
|
),
|
|
752
974
|
});
|
|
@@ -760,9 +982,9 @@ addContentStateOptions(
|
|
|
760
982
|
await handleError(error, globalOptions);
|
|
761
983
|
}
|
|
762
984
|
})
|
|
763
|
-
);
|
|
985
|
+
));
|
|
764
986
|
|
|
765
|
-
addContentStateOptions(
|
|
987
|
+
addLiveActivityActionOptions(addContentStateOptions(
|
|
766
988
|
activityCommand
|
|
767
989
|
.command("update")
|
|
768
990
|
.description("Update a Live Activity")
|
|
@@ -774,11 +996,13 @@ addContentStateOptions(
|
|
|
774
996
|
const apiKey = requireApiKey(globalOptions);
|
|
775
997
|
const client = createClient(apiKey);
|
|
776
998
|
const contentState = await loadContentState(options, "update");
|
|
999
|
+
const action = await loadLiveActivityAction(options);
|
|
777
1000
|
|
|
778
1001
|
const response = await client.liveActivities.updateLiveActivity({
|
|
779
1002
|
liveActivityUpdateRequest: toApiLiveActivityUpdateRequest(
|
|
780
1003
|
options.activityId,
|
|
781
|
-
contentState
|
|
1004
|
+
contentState,
|
|
1005
|
+
action
|
|
782
1006
|
),
|
|
783
1007
|
});
|
|
784
1008
|
|
|
@@ -790,9 +1014,9 @@ addContentStateOptions(
|
|
|
790
1014
|
await handleError(error, globalOptions);
|
|
791
1015
|
}
|
|
792
1016
|
})
|
|
793
|
-
);
|
|
1017
|
+
));
|
|
794
1018
|
|
|
795
|
-
addContentStateOptions(
|
|
1019
|
+
addLiveActivityActionOptions(addContentStateOptions(
|
|
796
1020
|
activityCommand
|
|
797
1021
|
.command("end")
|
|
798
1022
|
.description("End a Live Activity")
|
|
@@ -804,11 +1028,13 @@ addContentStateOptions(
|
|
|
804
1028
|
const apiKey = requireApiKey(globalOptions);
|
|
805
1029
|
const client = createClient(apiKey);
|
|
806
1030
|
const contentState = await loadContentState(options, "end");
|
|
1031
|
+
const action = await loadLiveActivityAction(options);
|
|
807
1032
|
|
|
808
1033
|
const response = await client.liveActivities.endLiveActivity({
|
|
809
1034
|
liveActivityEndRequest: toApiLiveActivityEndRequest(
|
|
810
1035
|
options.activityId,
|
|
811
|
-
contentState
|
|
1036
|
+
contentState,
|
|
1037
|
+
action
|
|
812
1038
|
),
|
|
813
1039
|
});
|
|
814
1040
|
|
|
@@ -821,7 +1047,43 @@ addContentStateOptions(
|
|
|
821
1047
|
}
|
|
822
1048
|
}),
|
|
823
1049
|
{ includeAutoDismiss: true }
|
|
824
|
-
);
|
|
1050
|
+
));
|
|
1051
|
+
|
|
1052
|
+
addLiveActivityActionOptions(addContentStateOptions(
|
|
1053
|
+
activityCommand
|
|
1054
|
+
.command("end-stream")
|
|
1055
|
+
.description("End a stateless Live Activity stream")
|
|
1056
|
+
.argument("<stream-key>", "Stable stream key")
|
|
1057
|
+
.action(async (streamKey, options) => {
|
|
1058
|
+
const globalOptions = program.opts();
|
|
1059
|
+
|
|
1060
|
+
try {
|
|
1061
|
+
const apiKey = requireApiKey(globalOptions);
|
|
1062
|
+
const client = createClient(apiKey);
|
|
1063
|
+
const contentState = await loadOptionalContentState(options, "end");
|
|
1064
|
+
const action = await loadLiveActivityAction(options);
|
|
1065
|
+
|
|
1066
|
+
const request =
|
|
1067
|
+
contentState !== undefined || action !== undefined
|
|
1068
|
+
? toApiLiveActivityStreamDeleteRequest(contentState, action)
|
|
1069
|
+
: undefined;
|
|
1070
|
+
|
|
1071
|
+
const response = await client.liveActivities.endStream(streamKey, request);
|
|
1072
|
+
|
|
1073
|
+
const activityId = response?.activityId ?? response?.activity_id;
|
|
1074
|
+
const operation = response?.operation;
|
|
1075
|
+
outputResult(response, globalOptions, [
|
|
1076
|
+
"Live Activity stream ended.",
|
|
1077
|
+
streamKey ? `Stream key: ${streamKey}` : null,
|
|
1078
|
+
operation ? `Operation: ${operation}` : null,
|
|
1079
|
+
activityId ? `Activity ID: ${activityId}` : null,
|
|
1080
|
+
]);
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
await handleError(error, globalOptions);
|
|
1083
|
+
}
|
|
1084
|
+
}),
|
|
1085
|
+
{ includeAutoDismiss: true }
|
|
1086
|
+
));
|
|
825
1087
|
|
|
826
1088
|
program.showHelpAfterError(true);
|
|
827
1089
|
program.parseAsync(process.argv);
|