activitysmith 0.1.7 → 1.0.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 +116 -38
- package/dist/generated/apis/PushNotificationsApi.d.ts +2 -2
- package/dist/generated/apis/PushNotificationsApi.js +2 -2
- package/dist/generated/models/index.d.ts +84 -2
- package/dist/generated/models/index.js +17 -1
- package/dist/src/ActivitySmith.d.ts +4 -2
- package/dist/src/ActivitySmith.js +26 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const activitysmith = new ActivitySmith({
|
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Push Notifications
|
|
36
36
|
|
|
37
37
|
### Send a Push Notification
|
|
38
38
|
|
|
@@ -41,13 +41,72 @@ const activitysmith = new ActivitySmith({
|
|
|
41
41
|
</p>
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
|
|
44
|
+
await activitysmith.notifications.send({
|
|
45
45
|
title: "New subscription 💸",
|
|
46
46
|
message: "Customer upgraded to Pro plan",
|
|
47
47
|
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Rich Push Notifications with Media
|
|
51
|
+
|
|
52
|
+
<p align="center">
|
|
53
|
+
<img src="https://cdn.activitysmith.com/features/rich-push-notification-with-image.png" alt="Rich push notification with image" width="680" />
|
|
54
|
+
</p>
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
```ts
|
|
57
|
+
await activitysmith.notifications.send({
|
|
58
|
+
title: "Homepage ready",
|
|
59
|
+
message: "Your agent finished the redesign.",
|
|
60
|
+
media: "https://cdn.example.com/output/homepage-v2.png",
|
|
61
|
+
redirection: "https://github.com/acme/web/pull/482",
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<img src="https://cdn.activitysmith.com/features/rich-push-notification-with-audio.png" alt="Rich push notification with audio" width="680" />
|
|
69
|
+
</p>
|
|
70
|
+
|
|
71
|
+
What will work:
|
|
72
|
+
|
|
73
|
+
- direct image URL: `.jpg`, `.png`, `.gif`, etc.
|
|
74
|
+
- direct audio file URL: `.mp3`, `.m4a`, etc.
|
|
75
|
+
- direct video file URL: `.mp4`, `.mov`, etc.
|
|
76
|
+
- URL that responds with a proper media `Content-Type`, even if the path has no extension
|
|
77
|
+
|
|
78
|
+
### Actionable Push Notifications
|
|
79
|
+
|
|
80
|
+
<p align="center">
|
|
81
|
+
<img src="https://cdn.activitysmith.com/features/actionable-push-notifications-2.png" alt="Actionable push notification example" width="680" />
|
|
82
|
+
</p>
|
|
83
|
+
|
|
84
|
+
Actionable push notifications can open a URL on tap or trigger actions when someone long-presses the notification.
|
|
85
|
+
Webhooks are executed by the ActivitySmith backend.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
await activitysmith.notifications.send({
|
|
89
|
+
title: "New subscription 💸",
|
|
90
|
+
message: "Customer upgraded to Pro plan",
|
|
91
|
+
redirection: "https://crm.example.com/customers/cus_9f3a1d", // Optional
|
|
92
|
+
actions: [
|
|
93
|
+
{
|
|
94
|
+
title: "Open CRM Profile",
|
|
95
|
+
type: "open_url",
|
|
96
|
+
url: "https://crm.example.com/customers/cus_9f3a1d",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
title: "Start Onboarding Workflow",
|
|
100
|
+
type: "webhook",
|
|
101
|
+
url: "https://hooks.example.com/activitysmith/onboarding/start",
|
|
102
|
+
method: "POST",
|
|
103
|
+
body: {
|
|
104
|
+
customer_id: "cus_9f3a1d",
|
|
105
|
+
plan: "pro",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
], // Optional (max 4)
|
|
109
|
+
});
|
|
51
110
|
```
|
|
52
111
|
|
|
53
112
|
## Live Activities
|
|
@@ -103,7 +162,7 @@ const activityId = start.activity_id;
|
|
|
103
162
|
</p>
|
|
104
163
|
|
|
105
164
|
```ts
|
|
106
|
-
|
|
165
|
+
await activitysmith.liveActivities.update({
|
|
107
166
|
activity_id: activityId,
|
|
108
167
|
content_state: {
|
|
109
168
|
title: "Nightly database backup",
|
|
@@ -112,8 +171,6 @@ const update = await activitysmith.liveActivities.update({
|
|
|
112
171
|
current_step: 2,
|
|
113
172
|
},
|
|
114
173
|
});
|
|
115
|
-
|
|
116
|
-
console.log(update.devices_notified);
|
|
117
174
|
```
|
|
118
175
|
|
|
119
176
|
#### End
|
|
@@ -123,7 +180,7 @@ console.log(update.devices_notified);
|
|
|
123
180
|
</p>
|
|
124
181
|
|
|
125
182
|
```ts
|
|
126
|
-
|
|
183
|
+
await activitysmith.liveActivities.end({
|
|
127
184
|
activity_id: activityId,
|
|
128
185
|
content_state: {
|
|
129
186
|
title: "Nightly database backup",
|
|
@@ -133,8 +190,6 @@ const end = await activitysmith.liveActivities.end({
|
|
|
133
190
|
auto_dismiss_minutes: 2,
|
|
134
191
|
},
|
|
135
192
|
});
|
|
136
|
-
|
|
137
|
-
console.log(end.success);
|
|
138
193
|
```
|
|
139
194
|
|
|
140
195
|
### Progress Type
|
|
@@ -198,45 +253,68 @@ await activitysmith.liveActivities.end({
|
|
|
198
253
|
});
|
|
199
254
|
```
|
|
200
255
|
|
|
201
|
-
|
|
256
|
+
### Live Activity Action
|
|
202
257
|
|
|
203
|
-
|
|
258
|
+
Just like Actionable Push Notifications, Live Activities can have a button that opens provided URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend.
|
|
259
|
+
|
|
260
|
+
<p align="center">
|
|
261
|
+
<img src="https://cdn.activitysmith.com/features/live-activity-with-action.png?v=20260319-1" alt="Live Activity with action" width="680" />
|
|
262
|
+
</p>
|
|
263
|
+
|
|
264
|
+
#### Open URL action
|
|
204
265
|
|
|
205
266
|
```ts
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
267
|
+
const start = await activitysmith.liveActivities.start({
|
|
268
|
+
content_state: {
|
|
269
|
+
title: "Deploying payments-api",
|
|
270
|
+
subtitle: "Running database migrations",
|
|
271
|
+
number_of_steps: 5,
|
|
272
|
+
current_step: 3,
|
|
273
|
+
type: "segmented_progress",
|
|
274
|
+
},
|
|
275
|
+
action: {
|
|
276
|
+
title: "Open Workflow",
|
|
277
|
+
type: "open_url",
|
|
278
|
+
url: "https://github.com/acme/payments-api/actions/runs/1234567890",
|
|
279
|
+
},
|
|
210
280
|
});
|
|
281
|
+
|
|
282
|
+
const activityId = start.activity_id;
|
|
211
283
|
```
|
|
212
284
|
|
|
213
|
-
|
|
285
|
+
#### Webhook action
|
|
214
286
|
|
|
215
|
-
|
|
216
|
-
|
|
287
|
+
```ts
|
|
288
|
+
await activitysmith.liveActivities.update({
|
|
289
|
+
activity_id: activityId,
|
|
290
|
+
content_state: {
|
|
291
|
+
title: "Reindexing product search",
|
|
292
|
+
subtitle: "Shard 7 of 12",
|
|
293
|
+
number_of_steps: 12,
|
|
294
|
+
current_step: 7,
|
|
295
|
+
},
|
|
296
|
+
action: {
|
|
297
|
+
title: "Pause Reindex",
|
|
298
|
+
type: "webhook",
|
|
299
|
+
url: "https://ops.example.com/hooks/search/reindex/pause",
|
|
300
|
+
method: "POST",
|
|
301
|
+
body: {
|
|
302
|
+
job_id: "reindex-2026-03-19",
|
|
303
|
+
requested_by: "activitysmith-node",
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Channels
|
|
310
|
+
|
|
311
|
+
Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
|
|
217
312
|
|
|
218
313
|
```ts
|
|
219
|
-
|
|
314
|
+
await activitysmith.notifications.send({
|
|
220
315
|
title: "New subscription 💸",
|
|
221
316
|
message: "Customer upgraded to Pro plan",
|
|
222
|
-
|
|
223
|
-
actions: [
|
|
224
|
-
{
|
|
225
|
-
title: "Open CRM Profile",
|
|
226
|
-
type: "open_url",
|
|
227
|
-
url: "https://crm.example.com/customers/cus_9f3a1d",
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
title: "Start Onboarding Workflow",
|
|
231
|
-
type: "webhook",
|
|
232
|
-
url: "https://hooks.example.com/activitysmith/onboarding/start",
|
|
233
|
-
method: "POST",
|
|
234
|
-
body: {
|
|
235
|
-
customer_id: "cus_9f3a1d",
|
|
236
|
-
plan: "pro",
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
], // Optional (max 4)
|
|
317
|
+
channels: ["sales", "customer-success"], // Optional
|
|
240
318
|
});
|
|
241
319
|
```
|
|
242
320
|
|
|
@@ -19,12 +19,12 @@ export interface SendPushNotificationRequest {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class PushNotificationsApi extends runtime.BaseAPI {
|
|
21
21
|
/**
|
|
22
|
-
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL
|
|
22
|
+
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL, optional media preview or playback when the notification is expanded, and up to 4 interactive actions. `media` cannot be combined with `actions`.
|
|
23
23
|
* Send a push notification
|
|
24
24
|
*/
|
|
25
25
|
sendPushNotificationRaw(requestParameters: SendPushNotificationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PushNotificationResponse>>;
|
|
26
26
|
/**
|
|
27
|
-
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL
|
|
27
|
+
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL, optional media preview or playback when the notification is expanded, and up to 4 interactive actions. `media` cannot be combined with `actions`.
|
|
28
28
|
* Send a push notification
|
|
29
29
|
*/
|
|
30
30
|
sendPushNotification(requestParameters: SendPushNotificationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PushNotificationResponse>;
|
|
@@ -20,7 +20,7 @@ const runtime = require("../runtime");
|
|
|
20
20
|
*/
|
|
21
21
|
class PushNotificationsApi extends runtime.BaseAPI {
|
|
22
22
|
/**
|
|
23
|
-
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL
|
|
23
|
+
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL, optional media preview or playback when the notification is expanded, and up to 4 interactive actions. `media` cannot be combined with `actions`.
|
|
24
24
|
* Send a push notification
|
|
25
25
|
*/
|
|
26
26
|
async sendPushNotificationRaw(requestParameters, initOverrides) {
|
|
@@ -47,7 +47,7 @@ class PushNotificationsApi extends runtime.BaseAPI {
|
|
|
47
47
|
return new runtime.JSONApiResponse(response);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL
|
|
50
|
+
* Sends a push notification to devices matched by API key scope and optional target channels. Supports optional redirection URL, optional media preview or playback when the notification is expanded, and up to 4 interactive actions. `media` cannot be combined with `actions`.
|
|
51
51
|
* Send a push notification
|
|
52
52
|
*/
|
|
53
53
|
async sendPushNotification(requestParameters, initOverrides) {
|
|
@@ -396,6 +396,55 @@ export interface ForbiddenError {
|
|
|
396
396
|
*/
|
|
397
397
|
message: string;
|
|
398
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Optional single action button shown in the Live Activity UI.
|
|
401
|
+
* @export
|
|
402
|
+
* @interface LiveActivityAction
|
|
403
|
+
*/
|
|
404
|
+
export interface LiveActivityAction {
|
|
405
|
+
[key: string]: any | any;
|
|
406
|
+
/**
|
|
407
|
+
* Button title displayed in the Live Activity UI.
|
|
408
|
+
* @type {string}
|
|
409
|
+
* @memberof LiveActivityAction
|
|
410
|
+
*/
|
|
411
|
+
title: string;
|
|
412
|
+
/**
|
|
413
|
+
*
|
|
414
|
+
* @type {LiveActivityActionType}
|
|
415
|
+
* @memberof LiveActivityAction
|
|
416
|
+
*/
|
|
417
|
+
type: LiveActivityActionType;
|
|
418
|
+
/**
|
|
419
|
+
* HTTPS URL. For open_url it is opened in browser. For webhook it is called by ActivitySmith backend.
|
|
420
|
+
* @type {string}
|
|
421
|
+
* @memberof LiveActivityAction
|
|
422
|
+
*/
|
|
423
|
+
url: string;
|
|
424
|
+
/**
|
|
425
|
+
* Webhook HTTP method. Used only when type=webhook.
|
|
426
|
+
* @type {LiveActivityWebhookMethod}
|
|
427
|
+
* @memberof LiveActivityAction
|
|
428
|
+
*/
|
|
429
|
+
method?: LiveActivityWebhookMethod;
|
|
430
|
+
/**
|
|
431
|
+
* Optional webhook payload body. Used only when type=webhook.
|
|
432
|
+
* @type {{ [key: string]: any; }}
|
|
433
|
+
* @memberof LiveActivityAction
|
|
434
|
+
*/
|
|
435
|
+
body?: {
|
|
436
|
+
[key: string]: any;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
*
|
|
441
|
+
* @export
|
|
442
|
+
*/
|
|
443
|
+
export declare const LiveActivityActionType: {
|
|
444
|
+
readonly OpenUrl: "open_url";
|
|
445
|
+
readonly Webhook: "webhook";
|
|
446
|
+
};
|
|
447
|
+
export type LiveActivityActionType = typeof LiveActivityActionType[keyof typeof LiveActivityActionType];
|
|
399
448
|
/**
|
|
400
449
|
* End an existing Live Activity by activity_id.
|
|
401
450
|
* @export
|
|
@@ -415,6 +464,12 @@ export interface LiveActivityEndRequest {
|
|
|
415
464
|
* @memberof LiveActivityEndRequest
|
|
416
465
|
*/
|
|
417
466
|
content_state: ContentStateEnd;
|
|
467
|
+
/**
|
|
468
|
+
*
|
|
469
|
+
* @type {LiveActivityAction}
|
|
470
|
+
* @memberof LiveActivityEndRequest
|
|
471
|
+
*/
|
|
472
|
+
action?: LiveActivityAction;
|
|
418
473
|
}
|
|
419
474
|
/**
|
|
420
475
|
* Returned after a Live Activity end event is sent or queued.
|
|
@@ -499,6 +554,12 @@ export interface LiveActivityStartRequest {
|
|
|
499
554
|
* @memberof LiveActivityStartRequest
|
|
500
555
|
*/
|
|
501
556
|
content_state: ContentStateStart;
|
|
557
|
+
/**
|
|
558
|
+
*
|
|
559
|
+
* @type {LiveActivityAction}
|
|
560
|
+
* @memberof LiveActivityStartRequest
|
|
561
|
+
*/
|
|
562
|
+
action?: LiveActivityAction;
|
|
502
563
|
/**
|
|
503
564
|
*
|
|
504
565
|
* @type {AlertPayload}
|
|
@@ -575,6 +636,12 @@ export interface LiveActivityUpdateRequest {
|
|
|
575
636
|
* @memberof LiveActivityUpdateRequest
|
|
576
637
|
*/
|
|
577
638
|
content_state: ContentStateUpdate;
|
|
639
|
+
/**
|
|
640
|
+
*
|
|
641
|
+
* @type {LiveActivityAction}
|
|
642
|
+
* @memberof LiveActivityUpdateRequest
|
|
643
|
+
*/
|
|
644
|
+
action?: LiveActivityAction;
|
|
578
645
|
}
|
|
579
646
|
/**
|
|
580
647
|
* Returned after a Live Activity update is sent or queued.
|
|
@@ -614,6 +681,15 @@ export interface LiveActivityUpdateResponse {
|
|
|
614
681
|
*/
|
|
615
682
|
timestamp: string;
|
|
616
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
*
|
|
686
|
+
* @export
|
|
687
|
+
*/
|
|
688
|
+
export declare const LiveActivityWebhookMethod: {
|
|
689
|
+
readonly Get: "GET";
|
|
690
|
+
readonly Post: "POST";
|
|
691
|
+
};
|
|
692
|
+
export type LiveActivityWebhookMethod = typeof LiveActivityWebhookMethod[keyof typeof LiveActivityWebhookMethod];
|
|
617
693
|
/**
|
|
618
694
|
*
|
|
619
695
|
* @export
|
|
@@ -715,13 +791,19 @@ export interface PushNotificationRequest {
|
|
|
715
791
|
*/
|
|
716
792
|
subtitle?: string;
|
|
717
793
|
/**
|
|
718
|
-
* Optional HTTPS URL
|
|
794
|
+
* Optional HTTPS URL for an image, audio file, or video that users can preview or play when they expand the notification. If `redirection` is omitted, tapping the notification opens this URL. Cannot be combined with `actions`.
|
|
795
|
+
* @type {string}
|
|
796
|
+
* @memberof PushNotificationRequest
|
|
797
|
+
*/
|
|
798
|
+
media?: string;
|
|
799
|
+
/**
|
|
800
|
+
* Optional HTTPS URL opened when user taps the notification body. Overrides the default tap target from `media` when both are provided.
|
|
719
801
|
* @type {string}
|
|
720
802
|
* @memberof PushNotificationRequest
|
|
721
803
|
*/
|
|
722
804
|
redirection?: string;
|
|
723
805
|
/**
|
|
724
|
-
* Optional interactive actions shown
|
|
806
|
+
* Optional interactive actions shown when users expand the notification. Cannot be combined with `media`.
|
|
725
807
|
* @type {Array<PushNotificationAction>}
|
|
726
808
|
* @memberof PushNotificationRequest
|
|
727
809
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PushNotificationWebhookMethod = exports.PushNotificationActionType = exports.ContentStateUpdateStepColorEnum = exports.ContentStateUpdateColorEnum = exports.ContentStateUpdateTypeEnum = exports.ContentStateStartStepColorEnum = exports.ContentStateStartColorEnum = exports.ContentStateStartTypeEnum = exports.ContentStateEndStepColorEnum = exports.ContentStateEndColorEnum = exports.ContentStateEndTypeEnum = void 0;
|
|
3
|
+
exports.PushNotificationWebhookMethod = exports.PushNotificationActionType = exports.LiveActivityWebhookMethod = exports.LiveActivityActionType = exports.ContentStateUpdateStepColorEnum = exports.ContentStateUpdateColorEnum = exports.ContentStateUpdateTypeEnum = exports.ContentStateStartStepColorEnum = exports.ContentStateStartColorEnum = exports.ContentStateStartTypeEnum = exports.ContentStateEndStepColorEnum = exports.ContentStateEndColorEnum = exports.ContentStateEndTypeEnum = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @export
|
|
6
6
|
*/
|
|
@@ -106,6 +106,22 @@ exports.ContentStateUpdateStepColorEnum = {
|
|
|
106
106
|
Orange: 'orange',
|
|
107
107
|
Yellow: 'yellow'
|
|
108
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @export
|
|
112
|
+
*/
|
|
113
|
+
exports.LiveActivityActionType = {
|
|
114
|
+
OpenUrl: 'open_url',
|
|
115
|
+
Webhook: 'webhook'
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @export
|
|
120
|
+
*/
|
|
121
|
+
exports.LiveActivityWebhookMethod = {
|
|
122
|
+
Get: 'GET',
|
|
123
|
+
Post: 'POST'
|
|
124
|
+
};
|
|
109
125
|
/**
|
|
110
126
|
*
|
|
111
127
|
* @export
|
|
@@ -3,6 +3,8 @@ export interface ActivitySmithOptions {
|
|
|
3
3
|
apiKey: string;
|
|
4
4
|
}
|
|
5
5
|
type PushRequestBody = Parameters<PushNotificationsApi["sendPushNotification"]>[0]["pushNotificationRequest"];
|
|
6
|
+
type PushSendParameters = Parameters<PushNotificationsApi["sendPushNotification"]>[0];
|
|
7
|
+
type PushRawParameters = Parameters<PushNotificationsApi["sendPushNotificationRaw"]>[0];
|
|
6
8
|
type SendInitOverrides = Parameters<PushNotificationsApi["sendPushNotification"]>[1];
|
|
7
9
|
type StartRequestBody = Parameters<LiveActivitiesApi["startLiveActivity"]>[0]["liveActivityStartRequest"];
|
|
8
10
|
type UpdateRequestBody = Parameters<LiveActivitiesApi["updateLiveActivity"]>[0]["liveActivityUpdateRequest"];
|
|
@@ -18,8 +20,8 @@ export declare class NotificationsResource {
|
|
|
18
20
|
private readonly api;
|
|
19
21
|
constructor(api: PushNotificationsApi);
|
|
20
22
|
send(request: PushSendRequest, initOverrides?: SendInitOverrides): Promise<import("../generated/models").PushNotificationResponse>;
|
|
21
|
-
sendPushNotification(
|
|
22
|
-
sendPushNotificationRaw(
|
|
23
|
+
sendPushNotification(requestParameters: PushSendParameters, initOverrides?: SendInitOverrides): Promise<import("../generated/models").PushNotificationResponse>;
|
|
24
|
+
sendPushNotificationRaw(requestParameters: PushRawParameters, initOverrides?: SendInitOverrides): Promise<import("../generated/runtime").ApiResponse<import("../generated/models").PushNotificationResponse>>;
|
|
23
25
|
}
|
|
24
26
|
export declare class LiveActivitiesResource {
|
|
25
27
|
private readonly api;
|
|
@@ -14,19 +14,40 @@ function withTargetChannels(request) {
|
|
|
14
14
|
target: { channels },
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
function hasMediaValue(media) {
|
|
18
|
+
if (typeof media === "string") {
|
|
19
|
+
return media.trim().length > 0;
|
|
20
|
+
}
|
|
21
|
+
return media !== null && media !== undefined;
|
|
22
|
+
}
|
|
23
|
+
function hasActionsValue(actions) {
|
|
24
|
+
if (Array.isArray(actions)) {
|
|
25
|
+
return actions.length > 0;
|
|
26
|
+
}
|
|
27
|
+
return actions !== null && actions !== undefined;
|
|
28
|
+
}
|
|
29
|
+
function assertValidPushRequest(request) {
|
|
30
|
+
if (hasMediaValue(request.media) && hasActionsValue(request.actions)) {
|
|
31
|
+
throw new Error("ActivitySmith: media cannot be combined with actions");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
17
34
|
class NotificationsResource {
|
|
18
35
|
constructor(api) {
|
|
19
36
|
this.api = api;
|
|
20
37
|
}
|
|
21
38
|
send(request, initOverrides) {
|
|
22
|
-
|
|
39
|
+
const normalized = withTargetChannels(request);
|
|
40
|
+
assertValidPushRequest(normalized);
|
|
41
|
+
return this.api.sendPushNotification({ pushNotificationRequest: normalized }, initOverrides);
|
|
23
42
|
}
|
|
24
43
|
// Backward-compatible alias.
|
|
25
|
-
sendPushNotification(
|
|
26
|
-
|
|
44
|
+
sendPushNotification(requestParameters, initOverrides) {
|
|
45
|
+
assertValidPushRequest(requestParameters.pushNotificationRequest);
|
|
46
|
+
return this.api.sendPushNotification(requestParameters, initOverrides);
|
|
27
47
|
}
|
|
28
|
-
sendPushNotificationRaw(
|
|
29
|
-
|
|
48
|
+
sendPushNotificationRaw(requestParameters, initOverrides) {
|
|
49
|
+
assertValidPushRequest(requestParameters.pushNotificationRequest);
|
|
50
|
+
return this.api.sendPushNotificationRaw(requestParameters, initOverrides);
|
|
30
51
|
}
|
|
31
52
|
}
|
|
32
53
|
exports.NotificationsResource = NotificationsResource;
|