@suprsend/node-sdk 1.10.0 → 1.11.1

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 CHANGED
@@ -1,22 +1,610 @@
1
1
  # suprsend-node-sdk
2
- This package can be included in a node project to easily integrate with `Suprsend` platform.
3
2
 
4
- Refer full documentation [here](https://docs.suprsend.com/docs/nodejs-sdk)
3
+ This package can be included in a node project to easily integrate with SuprSend platform.
5
4
 
6
- ### Installation
7
- `suprsend-node-sdk` is available as npm package. You can install using npm or yarn.
8
- ```bash
9
- npm install @suprsend/node-sdk
5
+ ## Installation
6
+
7
+ ```shell
8
+ npm install @suprsend/node-sdk@latest
9
+ ```
10
+
11
+ ## Initialization
12
+
13
+ ```javascript
14
+ const { Suprsend } = require("@suprsend/node-sdk");
15
+
16
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
17
+ ```
18
+
19
+ ## [Trigger workflow from API](https://docs.suprsend.com/docs/node-trigger-workflow-from-api)
20
+
21
+ It is a unified API to trigger workflow and doesn't require user creation before hand. If you are using our frontend SDK's to configure notifications and passing events and user properties from third-party data platforms like Segment, then [event-based trigger](https://docs.suprsend.com/docs/node-send-event-data) would be a better choice.
22
+
23
+ ```javascript
24
+ const { Suprsend, WorkflowTriggerRequest } = require("@suprsend/node-sdk");
25
+
26
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
27
+
28
+ // workflow payload
29
+ const body = {
30
+ workflow: "_workflow_slug_",
31
+ actor: {
32
+ distinct_id: "0fxxx8f74-xxxx-41c5-8752-xxxcb6911fb08",
33
+ name: "actor_1",
34
+ },
35
+ recipients: [
36
+ {
37
+ distinct_id: "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
38
+ $email: ["abc@example.com"],
39
+ name: "recipient_1",
40
+ },
41
+ ],
42
+ data: {
43
+ first_name: "User",
44
+ invoice_amount: "$5000",
45
+ invoice_id: "Invoice-1234",
46
+ },
47
+ };
48
+
49
+ const wf = new WorkflowTriggerRequest(body, {
50
+ tenant_id: "tenant_id",
51
+ idempotency_key: "_unique_request_identifier",
52
+ });
53
+
54
+ const response = supr_client.workflows.trigger(wf); // trigger workflow
55
+ response.then((res) => console.log("response", res));
56
+ ```
57
+
58
+ | Property | Type | Description |
59
+ | :----------------- | :--------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60
+ | workflow | string | Slug of designed workflow on SuprSend dashboard. You'll get the slug from workflow settings. |
61
+ | actor (_optional_) | string / object | Includes distinct_id and properties of the user who performed the action. You can use it for [cross-user notifications](https://docs.suprsend.com/docs/node-trigger-workflow-from-api#sending-cross-user-notifications) where you need to include actor properties in notification template. Actor properties can be added as `$actor.<prop>`. |
62
+ | recipients | array of string / array of objects | List of users who need to be notified. You can add upto 100 recipients in a workflow trigger. You can either pass recipients as an array of `distinct_ID` (if user is pre-synced in SuprSend database) or [define recipient information inline](https://docs.suprsend.com/docs/node-trigger-workflow-from-api#identifying-recipients-inline). |
63
+ | data | object | variable data required to render dynamic template content or workflow properties such as dynamic delay or channel override in send node. |
64
+ | tenant_id | string | trigger workflow for specific tenant/brand. |
65
+ | idempotency_key | string | unique identifier of the request. We'll be returning idempotency_key in our [outbound webhook response](https://docs.suprsend.com/docs/outbound-webhook). You can use it to map notification statuses and replies in your system. |
66
+
67
+ ### Response structure
68
+
69
+ ```javascript
70
+ {
71
+ "success": boolean,
72
+ "status": "success/fail",
73
+ "status_code": status_code
74
+ "message": "message_string"
75
+ }
76
+ ```
77
+
78
+ ### Sending notification to anonymous user
79
+
80
+ You can send notifications to anonymous users by passing `"is_transient": true` in your recipient object. This approach is recommended for scenarios where you need to send notifications to unregistered users without creating them in the SuprSend platform. The same way, you can pass `"is_transient": true` in your actor object to use actor properties in template without creating user profile.
81
+
82
+ ```javascript
83
+ // workflow payload
84
+ const workflow_body = {
85
+ workflow: "_workflow_slug_",
86
+ actor: {
87
+ is_transient: true, // for anonymous actor
88
+ name: "actor_1",
89
+ },
90
+ recipients: [
91
+ {
92
+ is_transient: true, // for anonymous recipient
93
+ $email: ["abc@example.com"],
94
+ name: "recipient_1",
95
+ },
96
+ ],
97
+ data: {
98
+ first_name: "User",
99
+ invoice_amount: "$5000",
100
+ invoice_id: "Invoice-1234",
101
+ },
102
+ };
103
+ ```
104
+
105
+ ### Trigger Multile workflows in bulk
106
+
107
+ ```javascript
108
+ const { Suprsend, WorkflowTriggerRequest } = require("@suprsend/node-sdk");
109
+
110
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
111
+
112
+ const wf1 = new WorkflowTriggerRequest(body1, {
113
+ tenant_id: "tenant_id1",
114
+ idempotency_key: "_unique_identifier_of_the_request_",
115
+ }); // workflow 1 request
116
+
117
+ const wf2 = new WorkflowTriggerRequest(body2); // workflow 2 request
118
+ // add as many workflow requests as you want
119
+
120
+ const bulk_ins = supr_client.workflows.bulk_trigger_instance(); // create bulk instance
121
+
122
+ bulk_ins.append(wf1, wf2); // add workflow instances to bulk instance
123
+
124
+ const response = bulk_ins.trigger(); // trigger workflows
125
+ response.then((res) => console.log("response", res));
126
+ ```
127
+
128
+ #### Bulk API Response
129
+
130
+ ```javascript
131
+ {
132
+ status: "success/fail/partial",
133
+ total: 10,
134
+ success: 10,
135
+ failure: 0,
136
+ failed_records: [{"record": {...}, "error": "error_str", "code": "<status_code>"}],
137
+ warnings: []
138
+ }
139
+ ```
140
+
141
+ ### Add file attachments (for email)
142
+
143
+ To add one or more attachments to a notification (viz. Email), call `wf_instance.add_attachment()` for each file with local-path or attachment url. Ensure that file_path is proper and public (if remote url), otherwise error will be raised..
144
+
145
+ ```javascript
146
+ wf_instance.add_attachment("/home/user/billing.pdf");
147
+ wf_instance.add_attachment("https://www.adobe.com/sample_file.pdf");
148
+ ```
149
+
150
+ > 🚧
151
+ > A single workflow body size (including attachment) must not exceed 100KB (100 x 1024 bytes).
152
+
153
+ ## [Updating User Profile](https://docs.suprsend.com/docs/node-create-user-profile)
154
+
155
+ ```javascript
156
+ const user = supr_client.user.get_instance("__uniq_distinct_id__");
157
+
158
+ // user methods mentioned below
159
+
160
+ const response = user.save();
161
+ response.then((res) => console.log("response", res));
162
+ ```
163
+
164
+ ### Response
165
+
166
+ ```javascript
167
+ {
168
+ "success": boolean,
169
+ "status": "success/fail",
170
+ "status_code": status_code
171
+ "message": "message_string"
172
+ }
173
+ ```
174
+
175
+ ### Add Channels
176
+
177
+ Use `user.add_*` method(s) to add user channels in a profile
178
+
179
+ ```javascript
180
+ user.add_email("user@example.com"); // add Email
181
+
182
+ user.add_sms("+15555555555"); // add SMS
183
+
184
+ user.add_whatsapp("+15555555555"); // to add Whatsapp
185
+
186
+ user.add_androidpush("__android_push_fcm_token__"); // add fcm push token
187
+
188
+ // set the optional provider value [fcm/xiaomi/oppo] if its not a fcm-token
189
+ user.add_androidpush("__android_push_xiaomi_token__", provider);
190
+
191
+ user.add_iospush("__iospush_token__"); // add apns push token
192
+
193
+ // add Slack using email
194
+ user.add_slack({
195
+ email: "user@example.com",
196
+ access_token: "xoxb-XXXXXXXX",
197
+ });
198
+
199
+ // add Slack if slack member_id is known
200
+ user.add_slack({
201
+ user_id: "U03XXXXXXXX",
202
+ access_token: "xoxb-XXXXXXXX",
203
+ });
204
+
205
+ // add Slack channel
206
+ user.add_slack({
207
+ channel_id: "CXXXXXXXX",
208
+ access_token: "xoxb-XXXXXXXX",
209
+ });
210
+
211
+ // add Slack incoming webhook
212
+ user.add_slack({
213
+ incoming_webhook: {
214
+ url: "https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX",
215
+ },
216
+ });
217
+
218
+ // add MS teams user or channel using conversation_id
219
+ user.add_ms_teams({
220
+ tenant_id: "c1981ab2-9aaf-xxxx-xxxx",
221
+ service_url: "https://smba.trafficmanager.net/amer",
222
+ conversation_id: "19:c1524d7c-a06f-456f-8abe-xxxx",
223
+ });
224
+
225
+ // add MS teams user using user_id
226
+ user.add_ms_teams({
227
+ tenant_id: "c1981ab2-9aaf-xxxx-xxxx",
228
+ service_url: "https://smba.trafficmanager.net/amer",
229
+ user_id: "29:1nsLcmJ2RKtYH6Cxxxx-xxxx",
230
+ });
231
+
232
+ // add MS teams using incoming webhook
233
+ user.add_ms_teams({
234
+ incoming_webhook: {
235
+ url: "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX",
236
+ },
237
+ });
238
+ ```
239
+
240
+ ### Remove Channels
241
+
242
+ Use `user.remove_*` method(s) to remove channels from a user profile. This method will detach provided value from the user profile specified channel.
243
+
244
+ ```javascript
245
+ user.remove_email("user@example.com"); // remove Email
246
+
247
+ user.remove_sms("+15555555555"); // remove SMS
248
+
249
+ user.remove_whatsapp("+15555555555"); // remove Whatsapp
250
+
251
+ user.remove_androidpush("__android_push_fcm_token__"); // remove fcm push token
252
+
253
+ // set the optional provider value [fcm/xiaomi/oppo] if its not a fcm-token
254
+ user.remove_androidpush("__android_push_xiaomi_token__", provider);
255
+
256
+ user.remove_iospush("__iospush_token__"); // add apns push token
257
+
258
+ // remove Slack email
259
+ user.remove_slack({
260
+ email: "user@example.com",
261
+ access_token: "xoxb-XXXXXXXX",
262
+ });
263
+
264
+ // remove Slack if slack member_id is known
265
+ user.remove_slack({
266
+ user_id: "U03XXXXXXXX",
267
+ access_token: "xoxb-XXXXXXXX",
268
+ });
269
+
270
+ // remove Slack channel
271
+ user.remove_slack({
272
+ channel_id: "CXXXXXXXX",
273
+ access_token: "xoxb-XXXXXXXX",
274
+ });
275
+
276
+ // remove Slack incoming webhook
277
+ user.remove_slack({
278
+ incoming_webhook: {
279
+ url: "https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX",
280
+ },
281
+ });
282
+
283
+ // remove MS teams user or channel using conversation_id
284
+ user.remove_ms_teams({
285
+ tenant_id: "c1981ab2-9aaf-xxxx-xxxx",
286
+ service_url: "https://smba.trafficmanager.net/amer",
287
+ conversation_id: "19:c1524d7c-a06f-456f-8abe-xxxx",
288
+ });
289
+
290
+ // remove MS teams user using user_id
291
+ user.remove_ms_teams({
292
+ tenant_id: "c1981ab2-9aaf-xxxx-xxxx",
293
+ service_url: "https://smba.trafficmanager.net/amer",
294
+ user_id: "29:1nsLcmJ2RKtYH6Cxxxx-xxxx",
295
+ });
296
+
297
+ // remove MS teams using incoming webhook
298
+ user.remove_ms_teams({
299
+ incoming_webhook: {
300
+ url: "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX",
301
+ },
302
+ });
303
+ ```
304
+
305
+ ### Remove User Channels in bulk
306
+
307
+ Call `user.unset()` method if you need to delete/unset all values of a user channel (ex: remove all emails attached to user).
308
+
309
+ ```javascript
310
+ user.unset("$email");
311
+ user.unset(["$email", "$sms", "$whatsapp"]);
312
+
313
+ // what value to pass to unset channels
314
+ // for email: $email
315
+ // for whatsapp: $whatsapp
316
+ // for SMS: $sms
317
+ // for androidpush tokens: $androidpush
318
+ // for iospush tokens: $iospush
319
+ // for webpush tokens: $webpush
320
+ // for slack: $slack
321
+ // for ms_teams: $ms_teams
10
322
  ```
11
323
 
12
- ### Initialization
13
- Initialize the Suprsend SDK
14
- ```node
15
- const {Suprsend} = require("@suprsend/node-sdk");
324
+ ### Other user methods
325
+
326
+ ```javascript
327
+ // 2-letter language code in "ISO 639-1 Alpha-2" format e.g. en (for English), es (for Spanish), fr (for French) etc.
328
+ user.set_preferred_language("en");
329
+
330
+ // set timezone property at user level in IANA timezone format
331
+ user.set_timezone("America/Los_Angeles");
332
+
333
+ // set custom properties on user
334
+ user.set(key, value); // key:string, value:any
335
+ user.set({ key1: "value1", key2: "value2" });
336
+
337
+ // similar to set but overriding value is not possible for this keys
338
+ user.set_once(key, value); // key:string, value:any
339
+ user.set_once({ key1: "value1", key2: "value2" });
340
+
341
+ // append a value to the list for a given property
342
+ user.append(key, value); // key:string, value:any
343
+ user.append({ key1: "value1", key2: "value2" });
344
+
345
+ // remove a value from the list for a given property
346
+ user.remove(key, value); // key:string, value:any
347
+ user.remove({ key1: "value1", key2: "value2" });
348
+
349
+ // add the given number(+/-) to an existing property
350
+ user.increment(key, value); // key:string, value:number
351
+ user.increment({ key1: "value1", key2: "value2" });
352
+
353
+ // remove a property permanently from user properties
354
+ user.unset(key); // key:string
355
+ user.unset(["key1", "key2"]);
356
+ ```
357
+
358
+ ### Bulk user update
359
+
360
+ ```javascript
361
+ const { Suprsend } = require("@suprsend/node-sdk");
362
+
363
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
364
+
365
+ const bulk_ins = supr_client.bulk_users.new_instance(); // create bulk instance
366
+
367
+ const user1 = supr_client.user.get_instance("distinct_id_1"); // create user 1 instance
368
+ user1.add_email("u1@example.com");
369
+
370
+ const user2 = supr_client.user.get_instance("distinct_id_2"); // create user 2 instance
371
+ user2.add_email("u2@example.com");
372
+
373
+ // adding users instance to bulk instance
374
+ bulk_ins.append(user1);
375
+ bulk_ins.append(user2);
376
+ // OR
377
+ bulk_ins.append(user1, user2);
378
+
379
+ const response = bulk_ins.save(); // trigger request
380
+ response.then((res) => console.log("response", res));
381
+ ```
382
+
383
+ #### Bulk API Response
384
+
385
+ ```javascript
386
+ {
387
+ status: "success/fail/partial",
388
+ total: 10,
389
+ success: 10,
390
+ failure: 0,
391
+ failed_records: [{"record": {...}, "error": "error_str", "code": "<status_code>"}],
392
+ warnings: []
393
+ }
394
+ ```
395
+
396
+ ## [Trigger Events](https://docs.suprsend.com/docs/node-send-event-data)
397
+
398
+ You can send event to Suprsend platform by using the `supr_client.track_event` method. If there is any workflow attached to that event, suprsend will trigger that workflow internally with data provided in the event. You can configure event to workflow from SuprSend Dashboard -> Workflows.
399
+
400
+ ```javascript
401
+ const { Suprsend, Event } = require("@suprsend/node-sdk");
402
+
403
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
404
+
405
+ // dictionary containing variables or info about event, If none use {}
406
+ const properties = {
407
+ "key1":"value1",
408
+ "key2":"value2"
409
+ }
410
+
411
+ const event = new Event(distinct_id, event_name, properties, {tenant_id : "your_tenant_id", idempotency_key="__uniq_request_id__"})
412
+
413
+ const response = supr_client.track_event(event)
414
+ response.then((res) => console.log("response", res));
415
+ ```
416
+
417
+ | Parameter | Description |
418
+ | :------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
419
+ | distinct_id | unique id of subscriber performing the event |
420
+ | event_name | string identifier for the event like `product_purchased` |
421
+ | properties | information about event like `first_name`. Event properties will be used to pass template variables. Properties keys cannot start with `ss_` or `$` |
422
+ | tenant_id (optional) | tenant id of the tenant |
423
+ | idempotency_key (optional) | unique key in the request call for [idempotent requests](https://docs.suprsend.com/docs/node-send-event-data#idempotent-requests) |
424
+
425
+ ### Response structure
426
+
427
+ ```javascript
428
+ {
429
+ "success": boolean,
430
+ "status": "success/fail",
431
+ "status_code": status_code
432
+ "message": "message_string"
433
+ }
434
+ ```
435
+
436
+ ### Trigger multiple events in bulk
437
+
438
+ ```javascript
439
+ const { Suprsend, Event } = require("@suprsend/node-sdk");
440
+
441
+ const supr_client = new Suprsend("_workspace_key_", "_workspace_secret_");
442
+
443
+ const bulk_ins = supr_client.bulk_events.new_instance(); // create bulk instance
444
+
445
+ const event1 = new Event("distinct_id1", "event_name1", { k1: "v1" }); // create event 1
446
+ const event2 = new Event("distinct_id2", "event_name2", { k2: "v2" }); // create event 2
447
+
448
+ // add event instance to bulk instance
449
+ bulk_ins.append(event1);
450
+ bulk_ins.append(event2);
451
+ // OR
452
+ bulk_ins.append(event1, event2);
453
+
454
+ const response = bulk_ins.trigger(); // trigger request
455
+ response.then((res) => console.log("response", res));
456
+ ```
457
+
458
+ #### Bulk API Response
459
+
460
+ ```javascript
461
+ {
462
+ status: "success/fail/partial",
463
+ total: 10,
464
+ success: 10,
465
+ failure: 0,
466
+ failed_records: [{"record": {...}, "error": "error_str", "code": "<status_code>"}],
467
+ warnings: []
468
+ }
469
+ ```
470
+
471
+ ### Add file attachments (for email)
472
+
473
+ To add one or more attachments to a notification (viz. Email), call `event.add_attachment()` for each file with local path or remote url. Ensure that file_path is proper and public (if remote url), otherwise error will be raised.
474
+
475
+ ```javascript
476
+ event.add_attachment("/home/user/billing.pdf");
477
+ event.add_attachment("https://www.adobe.com/sample_file.pdf");
478
+ ```
479
+
480
+ > 🚧
481
+ > A single event instance size (including attachment) must not exceed 100KB (100 x 1024 bytes).
482
+
483
+ ## [Tenants/Brands](https://docs.suprsend.com/docs/node-brands)
484
+
485
+ By default, SuprSend creates a tenant with tenant_id="default" (representing your organization) in each of your workspaces. You can create more tenants using one of our backend SDKs. After creating tenants you can use the `tenant_id` field in `Event` and `WorkflowTriggerRequest` to trigger notifications to specific tenant.
486
+
487
+ ### Tenant data structure
488
+
489
+ ```json
490
+ {
491
+ "tenant_id": "br-01",
492
+ "tenant_name": "Awesome Brand",
493
+ "logo": "https://ik.imagekit.io/l0quatz6utm/suprsend/staging/media/suprsend-only-logo_c8aa27faef118418e8c5bd7b31a1cafc74e09200.png",
494
+ "primary_color": "#ff0000",
495
+ "secondary_color": "#00ff00",
496
+ "tertiary_color": "#0000ff",
497
+ "social_links": {
498
+ "website": "https://suprsend.com",
499
+ "facebook": "",
500
+ "linkedin": "",
501
+ "twitter": "",
502
+ "instagram": "",
503
+ "medium": "",
504
+ "discord": "",
505
+ "telegram": "",
506
+ "youtube": ""
507
+ },
508
+ "embedded_preference_url": "",
509
+ "hosted_preference_domain": "",
510
+ "properties": {
511
+ "prop1": "value1",
512
+ "prop2": "value2"
513
+ }
514
+ }
515
+ ```
516
+
517
+ ### Tenant methods
518
+
519
+ ```javascript
520
+ const { Suprsend } = require("@suprsend/node-sdk");
16
521
 
17
- // Initialize SDK
18
522
  const supr_client = new Suprsend("workspace_key", "workspace_secret");
523
+
524
+ // create or update tenant
525
+ const response = supr_client.tenants.upsert(tenant_id, tenant_payload);
526
+
527
+ // get specific tenant details
528
+ const response = supr_client.tenants.get(tenant_id);
529
+
530
+ // get tenants list
531
+ const response = supr_client.tenants.list({ limit: 20, offset: 0 });
532
+
533
+ response.then((res) => console.log("response", res));
534
+ ```
535
+
536
+ ## [Lists](https://docs.suprsend.com/docs/node-lists)
537
+
538
+ Lists lets you create a list of subscribers. You can then send bulk messages to all the subscribers in the list with a single API call.
539
+
540
+ ```javascript
541
+ const { Suprsend } = require("@suprsend/node-sdk");
542
+
543
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
544
+
545
+ // create list
546
+ const response = supr_client.subscriber_lists.create({
547
+ list_id: "_list_id_",
548
+ list_name: "_list_name_",
549
+ list_description: "_some sample descritpion for list_",
550
+ });
551
+
552
+ // get list details
553
+ const response = supr_client.subscriber_lists.get("_list_id_");
554
+
555
+ // get list of lists
556
+ const response = supr_client.subscriber_lists.get_all({ limit: 20, offset: 0 });
557
+
558
+ // add subscriber to the list
559
+ const response = supr_client.subscriber_lists.add("_list_id_", [
560
+ "_distinct_id1_",
561
+ "_distinct_id2_",
562
+ ]);
563
+
564
+ // remove subscribers from list
565
+ const response = supr_client.subscriber_lists.remove("_list_id_", [
566
+ "_distinct_id1_",
567
+ "_distinct_id2_",
568
+ ]);
569
+
570
+ response.then((res) => console.log("response", res));
571
+ ```
572
+
573
+ ### [Trigger broadcast notifications to list](https://docs.suprsend.com/docs/node-broadcast)
574
+
575
+ ```javascript
576
+ const { Suprsend, SubscriberListBroadcast } = require("@suprsend/node-sdk");
577
+
578
+ const supr_client = new Suprsend("workspace_key", "workspace_secret");
579
+
580
+ // prepare payload
581
+ const broadcast_body = {
582
+ list_id: "_list_id_",
583
+ template: "_template_slug_",
584
+ notification_category: "_",
585
+ channels: [],
586
+ delay: "_time_delay_",
587
+ trigger_at: "_ISO_timestamp_",
588
+ data: {
589
+ key1: "value1",
590
+ key2: "value2",
591
+ },
592
+ };
593
+
594
+ const broadcast_instance = new SubscriberListBroadcast(broadcast_body, {tenant_id : "your_tenant_id", idempotency_key="__uniq_request_id__"}); // create broadcast instance
595
+
596
+ const response = supr_client.subscriber_lists.broadcast(inst); // trigger broadcast
597
+ response.then((res) => console.log("response", res));
598
+ ```
599
+
600
+ #### Add file attachments in broadcast (for email)
601
+
602
+ To add one or more attachments to a notification (viz. Email), call `broadcast_instance.add_attachment()` for each file with local-path or attachment url. Ensure that file_path is proper and public (if remote url), otherwise error will be raised.
603
+
604
+ ```javascript
605
+ broadcast_instance.add_attachment("/home/user/billing.pdf");
606
+ broadcast_instance.add_attachment("https://www.adobe.com/sample_file.pdf");
19
607
  ```
20
608
 
21
- ### License
22
- MIT © [https://github.com/suprsend](https://github.com/suprsend)
609
+ > 🚧
610
+ > A single broadcast instance size (including attachment) must not exceed 100KB (100 x 1024 bytes).
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ var _subscribers_bulk = _interopRequireDefault(require("./subscribers_bulk"));
45
45
  var _subscriber_list = require("./subscriber_list");
46
46
  var _brands = _interopRequireDefault(require("./brands"));
47
47
  var _tenant = _interopRequireDefault(require("./tenant"));
48
+ var _object = _interopRequireDefault(require("./object"));
48
49
  var _constants = require("./constants");
49
50
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
50
51
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -67,6 +68,7 @@ var Suprsend = /*#__PURE__*/function () {
67
68
  this.brands = new _brands["default"](this);
68
69
  this.tenants = new _tenant["default"](this);
69
70
  this.workflows = new _workflow_api["default"](this);
71
+ this.objects = new _object["default"](this);
70
72
  this.subscriber_lists = new _subscriber_list.SubscriberListsApi(this);
71
73
  this._validate();
72
74
  }