@digisglobal/omnivox-sdk 0.7.0 → 0.9.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/dist/index.cjs +151 -33
- package/dist/index.d.cts +216 -43
- package/dist/index.d.ts +216 -43
- package/dist/index.js +151 -33
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -226,9 +226,15 @@ var getChannelsControllerVerifyUrl = (id, channelId) => {
|
|
|
226
226
|
var getWhatsAppBusinessAccountsControllerListUrl = (id) => {
|
|
227
227
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
|
|
228
228
|
};
|
|
229
|
+
var getWhatsAppBusinessAccountsControllerCreateUrl = (id) => {
|
|
230
|
+
return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
|
|
231
|
+
};
|
|
229
232
|
var getWhatsAppBusinessAccountsControllerFindOneUrl = (id, wabaRowId) => {
|
|
230
233
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
|
|
231
234
|
};
|
|
235
|
+
var getWhatsAppBusinessAccountsControllerUpdateNameUrl = (id, wabaRowId) => {
|
|
236
|
+
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
|
|
237
|
+
};
|
|
232
238
|
var getAgentsControllerCreateUrl = () => {
|
|
233
239
|
return `/api/v1/agents`;
|
|
234
240
|
};
|
|
@@ -248,12 +254,25 @@ var getAgentsControllerFindOneUrl = (id) => {
|
|
|
248
254
|
var getTemplatesControllerAuthorDraftUrl = (id, wabaId) => {
|
|
249
255
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
|
|
250
256
|
};
|
|
257
|
+
var getTemplatesControllerListUrl = (id, wabaId, params) => {
|
|
258
|
+
const normalizedParams = new URLSearchParams();
|
|
259
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
260
|
+
if (value !== void 0) {
|
|
261
|
+
normalizedParams.append(key, value === null ? "null" : String(value));
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
const stringifiedParams = normalizedParams.toString();
|
|
265
|
+
return stringifiedParams.length > 0 ? `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates?${stringifiedParams}` : `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
|
|
266
|
+
};
|
|
251
267
|
var getTemplatesControllerImportApprovedUrl = (id, wabaId) => {
|
|
252
268
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/import`;
|
|
253
269
|
};
|
|
254
270
|
var getTemplatesControllerForkDraftUrl = (id, wabaId, templateId) => {
|
|
255
271
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
|
|
256
272
|
};
|
|
273
|
+
var getTemplatesControllerGetByIdUrl = (id, wabaId, templateId) => {
|
|
274
|
+
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
|
|
275
|
+
};
|
|
257
276
|
var getTemplatesControllerGetHistoryUrl = (id, wabaId, templateId) => {
|
|
258
277
|
return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}/history`;
|
|
259
278
|
};
|
|
@@ -301,6 +320,9 @@ var getCannedResponsesControllerPatchUrl = (id) => {
|
|
|
301
320
|
var getCannedResponsesControllerDeleteUrl = (id) => {
|
|
302
321
|
return `/api/v1/canned-responses/${id}`;
|
|
303
322
|
};
|
|
323
|
+
var getCannedResponsesControllerDuplicateUrl = (id) => {
|
|
324
|
+
return `/api/v1/canned-responses/${id}/duplicate`;
|
|
325
|
+
};
|
|
304
326
|
var getAttachmentsControllerUploadUrl = () => {
|
|
305
327
|
return `/api/v1/attachments`;
|
|
306
328
|
};
|
|
@@ -399,7 +421,7 @@ function createTenantsModule(options) {
|
|
|
399
421
|
url,
|
|
400
422
|
buildInit("POST", { body: JSON.stringify(body) })
|
|
401
423
|
);
|
|
402
|
-
return
|
|
424
|
+
return parseEnvelopedResponse(res);
|
|
403
425
|
},
|
|
404
426
|
/**
|
|
405
427
|
* Revoke an existing API key immediately.
|
|
@@ -409,7 +431,7 @@ function createTenantsModule(options) {
|
|
|
409
431
|
const path = getApiKeysControllerRevokeUrl(tenantId, keyId);
|
|
410
432
|
const url = `${baseUrl}${path}`;
|
|
411
433
|
const res = await fetch(url, buildInit("DELETE"));
|
|
412
|
-
return
|
|
434
|
+
return parseEnvelopedResponse(res);
|
|
413
435
|
}
|
|
414
436
|
}
|
|
415
437
|
};
|
|
@@ -438,7 +460,7 @@ function createAgentsModule(options) {
|
|
|
438
460
|
const path = getAgentsControllerCreateUrl();
|
|
439
461
|
const url = `${baseUrl}${path}`;
|
|
440
462
|
const res = await fetch(url, buildInit("POST", input));
|
|
441
|
-
return
|
|
463
|
+
return parseEnvelopedResponse(res);
|
|
442
464
|
},
|
|
443
465
|
/**
|
|
444
466
|
* List agents for the authenticated tenant (paginated, sorted deterministically).
|
|
@@ -460,7 +482,7 @@ function createAgentsModule(options) {
|
|
|
460
482
|
const path = getAgentsControllerFindOneUrl(id);
|
|
461
483
|
const url = `${baseUrl}${path}`;
|
|
462
484
|
const res = await fetch(url, buildInit("GET"));
|
|
463
|
-
return
|
|
485
|
+
return parseEnvelopedResponse(res);
|
|
464
486
|
}
|
|
465
487
|
};
|
|
466
488
|
}
|
|
@@ -490,7 +512,7 @@ function createChannelsModule(options) {
|
|
|
490
512
|
const path = getChannelsControllerCreateUrl(tenantId);
|
|
491
513
|
const url = `${baseUrl}${path}`;
|
|
492
514
|
const res = await fetch(url, buildInit("POST", body));
|
|
493
|
-
return
|
|
515
|
+
return parseEnvelopedResponse(res);
|
|
494
516
|
},
|
|
495
517
|
/**
|
|
496
518
|
* Get a single channel by id (config + name/status/isDefault/type +
|
|
@@ -501,7 +523,7 @@ function createChannelsModule(options) {
|
|
|
501
523
|
const path = getChannelsControllerFindOneUrl(tenantId, channelId);
|
|
502
524
|
const url = `${baseUrl}${path}`;
|
|
503
525
|
const res = await fetch(url, buildInit("GET"));
|
|
504
|
-
return
|
|
526
|
+
return parseEnvelopedResponse(res);
|
|
505
527
|
},
|
|
506
528
|
/**
|
|
507
529
|
* Update a channel (name/status/isDefault/config; Email may rotate secret).
|
|
@@ -511,7 +533,7 @@ function createChannelsModule(options) {
|
|
|
511
533
|
const path = getChannelsControllerUpdateUrl(tenantId, channelId);
|
|
512
534
|
const url = `${baseUrl}${path}`;
|
|
513
535
|
const res = await fetch(url, buildInit("PATCH", body));
|
|
514
|
-
return
|
|
536
|
+
return parseEnvelopedResponse(res);
|
|
515
537
|
},
|
|
516
538
|
/**
|
|
517
539
|
* Verify a channel through its adapter; on success sets lastVerifiedAt.
|
|
@@ -549,7 +571,7 @@ function createContactsModule(options) {
|
|
|
549
571
|
const path = getContactsControllerCreateUrl();
|
|
550
572
|
const url = `${baseUrl}${path}`;
|
|
551
573
|
const res = await fetch(url, buildInit("POST", input));
|
|
552
|
-
return
|
|
574
|
+
return parseEnvelopedResponse(res);
|
|
553
575
|
},
|
|
554
576
|
/**
|
|
555
577
|
* Search contacts by display name or raw identifier.
|
|
@@ -576,7 +598,7 @@ function createContactsModule(options) {
|
|
|
576
598
|
const path = getContactsControllerGetDetailUrl(id);
|
|
577
599
|
const url = `${baseUrl}${path}`;
|
|
578
600
|
const res = await fetch(url, buildInit("GET"));
|
|
579
|
-
return
|
|
601
|
+
return parseEnvelopedResponse(res);
|
|
580
602
|
},
|
|
581
603
|
/**
|
|
582
604
|
* Return the tenant's tag catalog and custom-field definitions.
|
|
@@ -586,7 +608,7 @@ function createContactsModule(options) {
|
|
|
586
608
|
const path = getContactsControllerGetMetadataUrl();
|
|
587
609
|
const url = `${baseUrl}${path}`;
|
|
588
610
|
const res = await fetch(url, buildInit("GET"));
|
|
589
|
-
return
|
|
611
|
+
return parseEnvelopedResponse(res);
|
|
590
612
|
},
|
|
591
613
|
/**
|
|
592
614
|
* Partially update a contact.
|
|
@@ -596,7 +618,7 @@ function createContactsModule(options) {
|
|
|
596
618
|
const path = getContactsControllerPatchUrl(id);
|
|
597
619
|
const url = `${baseUrl}${path}`;
|
|
598
620
|
const res = await fetch(url, buildInit("PATCH", input));
|
|
599
|
-
return
|
|
621
|
+
return parseEnvelopedResponse(res);
|
|
600
622
|
},
|
|
601
623
|
/**
|
|
602
624
|
* Add a channel identity to an existing contact.
|
|
@@ -606,7 +628,7 @@ function createContactsModule(options) {
|
|
|
606
628
|
const path = getContactsControllerAddIdentityUrl(id);
|
|
607
629
|
const url = `${baseUrl}${path}`;
|
|
608
630
|
const res = await fetch(url, buildInit("POST", input));
|
|
609
|
-
return
|
|
631
|
+
return parseEnvelopedResponse(res);
|
|
610
632
|
}
|
|
611
633
|
};
|
|
612
634
|
}
|
|
@@ -635,7 +657,7 @@ function createConversationsModule(options) {
|
|
|
635
657
|
const path = getConversationsControllerReopenOrCreateUrl();
|
|
636
658
|
const url = `${baseUrl}${path}`;
|
|
637
659
|
const res = await fetch(url, buildInit("POST", input));
|
|
638
|
-
return
|
|
660
|
+
return parseEnvelopedResponse(res);
|
|
639
661
|
},
|
|
640
662
|
/**
|
|
641
663
|
* List conversations with optional filters (paginated, sorted deterministically).
|
|
@@ -663,7 +685,7 @@ function createConversationsModule(options) {
|
|
|
663
685
|
const path = getConversationsControllerUpdateStatusUrl(id);
|
|
664
686
|
const url = `${baseUrl}${path}`;
|
|
665
687
|
const res = await fetch(url, buildInit("PATCH", input));
|
|
666
|
-
return
|
|
688
|
+
return parseEnvelopedResponse(res);
|
|
667
689
|
},
|
|
668
690
|
/**
|
|
669
691
|
* Assign a conversation to an agent.
|
|
@@ -673,7 +695,7 @@ function createConversationsModule(options) {
|
|
|
673
695
|
const path = getConversationsControllerAssignUrl(id);
|
|
674
696
|
const url = `${baseUrl}${path}`;
|
|
675
697
|
const res = await fetch(url, buildInit("PATCH", input));
|
|
676
|
-
return
|
|
698
|
+
return parseEnvelopedResponse(res);
|
|
677
699
|
},
|
|
678
700
|
/**
|
|
679
701
|
* List lobby entries awaiting pickup (paginated, sorted by receivedAt DESC).
|
|
@@ -695,18 +717,18 @@ function createConversationsModule(options) {
|
|
|
695
717
|
const path = getConversationsControllerFindOneUrl(id);
|
|
696
718
|
const url = `${baseUrl}${path}`;
|
|
697
719
|
const res = await fetch(url, buildInit("GET"));
|
|
698
|
-
return
|
|
720
|
+
return parseEnvelopedResponse(res);
|
|
699
721
|
},
|
|
700
722
|
/**
|
|
701
723
|
* Pick up a lobby entry (atomic 4-step transaction).
|
|
702
|
-
* Returns the resulting conversation.
|
|
724
|
+
* Returns the resulting conversation + entry ids.
|
|
703
725
|
* Calls POST /api/v1/conversations/lobby/:entryId/pickup.
|
|
704
726
|
*/
|
|
705
727
|
async pickup(entryId, input) {
|
|
706
728
|
const path = getConversationsControllerPickupLobbyEntryUrl(entryId);
|
|
707
729
|
const url = `${baseUrl}${path}`;
|
|
708
730
|
const res = await fetch(url, buildInit("POST", input));
|
|
709
|
-
return
|
|
731
|
+
return parseEnvelopedResponse(res);
|
|
710
732
|
},
|
|
711
733
|
/**
|
|
712
734
|
* List APPROVED + SENDABLE WhatsApp templates eligible to re-open an
|
|
@@ -718,7 +740,7 @@ function createConversationsModule(options) {
|
|
|
718
740
|
const path = getConversationsControllerGetWhatsAppRecoveryOptionsUrl(id);
|
|
719
741
|
const url = `${baseUrl}${path}`;
|
|
720
742
|
const res = await fetch(url, buildInit("GET"));
|
|
721
|
-
return
|
|
743
|
+
return parseEnvelopedResponse(res);
|
|
722
744
|
}
|
|
723
745
|
};
|
|
724
746
|
}
|
|
@@ -746,7 +768,7 @@ function createMessagesModule(options) {
|
|
|
746
768
|
const path = getMessagesControllerSendUrl();
|
|
747
769
|
const url = `${baseUrl}${path}`;
|
|
748
770
|
const res = await fetch(url, buildInit("POST", input));
|
|
749
|
-
return
|
|
771
|
+
return parseEnvelopedResponse(res);
|
|
750
772
|
},
|
|
751
773
|
/**
|
|
752
774
|
* List messages in a conversation (newest first, paginated).
|
|
@@ -774,7 +796,7 @@ function createMessagesModule(options) {
|
|
|
774
796
|
const path = getMessagesControllerGetByIdUrl(id);
|
|
775
797
|
const url = `${baseUrl}${path}`;
|
|
776
798
|
const res = await fetch(url, buildInit("GET"));
|
|
777
|
-
return
|
|
799
|
+
return parseEnvelopedResponse(res);
|
|
778
800
|
},
|
|
779
801
|
/**
|
|
780
802
|
* Soft-delete a message (sets deletedAt; row preserved).
|
|
@@ -796,7 +818,7 @@ function createMessagesModule(options) {
|
|
|
796
818
|
const path = getMessagesControllerSendTemplateUrl();
|
|
797
819
|
const url = `${baseUrl}${path}`;
|
|
798
820
|
const res = await fetch(url, buildInit("POST", input));
|
|
799
|
-
return
|
|
821
|
+
return parseEnvelopedResponse(res);
|
|
800
822
|
}
|
|
801
823
|
};
|
|
802
824
|
}
|
|
@@ -820,6 +842,38 @@ function createTemplatesModule(options) {
|
|
|
820
842
|
* WhatsApp template submodule — WABA-scoped operations.
|
|
821
843
|
*/
|
|
822
844
|
whatsapp: {
|
|
845
|
+
/**
|
|
846
|
+
* List a WhatsApp Business Account's templates (paginated, optionally status-filtered and name-searchable).
|
|
847
|
+
* Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
|
|
848
|
+
*/
|
|
849
|
+
async list(tenantId, wabaId, opts) {
|
|
850
|
+
const { page, pageSize } = buildPageParams(opts);
|
|
851
|
+
const path = getTemplatesControllerListUrl(tenantId, wabaId, {
|
|
852
|
+
page,
|
|
853
|
+
pageSize,
|
|
854
|
+
...opts.status ? { status: opts.status } : {},
|
|
855
|
+
...opts.q ? { q: opts.q } : {}
|
|
856
|
+
});
|
|
857
|
+
const url = `${baseUrl}${path}`;
|
|
858
|
+
const res = await fetch(url, buildInit("GET"));
|
|
859
|
+
return parseResponse(res);
|
|
860
|
+
},
|
|
861
|
+
/**
|
|
862
|
+
* Get a single template together with its current (latest) version.
|
|
863
|
+
* Language/status and other version-scoped fields are nested under
|
|
864
|
+
* `currentVersion` — not at the top level (see WhatsAppTemplateDetail).
|
|
865
|
+
* Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId.
|
|
866
|
+
*/
|
|
867
|
+
async getById(tenantId, wabaId, templateId) {
|
|
868
|
+
const path = getTemplatesControllerGetByIdUrl(
|
|
869
|
+
tenantId,
|
|
870
|
+
wabaId,
|
|
871
|
+
templateId
|
|
872
|
+
);
|
|
873
|
+
const url = `${baseUrl}${path}`;
|
|
874
|
+
const res = await fetch(url, buildInit("GET"));
|
|
875
|
+
return parseEnvelopedResponse(res);
|
|
876
|
+
},
|
|
823
877
|
/**
|
|
824
878
|
* Author a new DRAFT template (version 1) under a WhatsApp Business Account.
|
|
825
879
|
* Calls POST /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
|
|
@@ -855,7 +909,11 @@ function createTemplatesModule(options) {
|
|
|
855
909
|
return parseEnvelopedResponse(res);
|
|
856
910
|
},
|
|
857
911
|
/**
|
|
858
|
-
*
|
|
912
|
+
* Get the full version + status-event history for a template.
|
|
913
|
+
*
|
|
914
|
+
* Returns a single OBJECT (see WhatsAppTemplateHistory) — template-level
|
|
915
|
+
* fields plus a `versions` array ordered by versionNumber ascending, each
|
|
916
|
+
* version carrying its own `statusEvents`. NOT a flat array of events.
|
|
859
917
|
* Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId/history.
|
|
860
918
|
*/
|
|
861
919
|
async history(tenantId, wabaId, templateId) {
|
|
@@ -903,7 +961,11 @@ function createTemplatesModule(options) {
|
|
|
903
961
|
*/
|
|
904
962
|
async list(opts) {
|
|
905
963
|
const { page, pageSize } = buildPageParams(opts);
|
|
906
|
-
const path = getEmailTemplatesControllerListUrl({
|
|
964
|
+
const path = getEmailTemplatesControllerListUrl({
|
|
965
|
+
page,
|
|
966
|
+
pageSize,
|
|
967
|
+
...opts.q ? { q: opts.q } : {}
|
|
968
|
+
});
|
|
907
969
|
const url = `${baseUrl}${path}`;
|
|
908
970
|
const res = await fetch(url, buildInit("GET"));
|
|
909
971
|
return parseResponse(res);
|
|
@@ -966,7 +1028,12 @@ function createCannedResponsesModule(options) {
|
|
|
966
1028
|
*/
|
|
967
1029
|
async list(opts) {
|
|
968
1030
|
const { page, pageSize } = buildPageParams(opts);
|
|
969
|
-
const path = getCannedResponsesControllerListUrl({
|
|
1031
|
+
const path = getCannedResponsesControllerListUrl({
|
|
1032
|
+
page,
|
|
1033
|
+
pageSize,
|
|
1034
|
+
...opts.category ? { category: opts.category } : {},
|
|
1035
|
+
...opts.channel ? { channel: opts.channel } : {}
|
|
1036
|
+
});
|
|
970
1037
|
const url = `${baseUrl}${path}`;
|
|
971
1038
|
const res = await fetch(url, buildInit("GET"));
|
|
972
1039
|
return parseResponse(res);
|
|
@@ -981,7 +1048,9 @@ function createCannedResponsesModule(options) {
|
|
|
981
1048
|
const path = getCannedResponsesControllerListUrl({
|
|
982
1049
|
page,
|
|
983
1050
|
pageSize,
|
|
984
|
-
q: opts.q
|
|
1051
|
+
q: opts.q,
|
|
1052
|
+
...opts.category ? { category: opts.category } : {},
|
|
1053
|
+
...opts.channel ? { channel: opts.channel } : {}
|
|
985
1054
|
});
|
|
986
1055
|
const url = `${baseUrl}${path}`;
|
|
987
1056
|
const res = await fetch(url, buildInit("GET"));
|
|
@@ -995,17 +1064,17 @@ function createCannedResponsesModule(options) {
|
|
|
995
1064
|
const path = getCannedResponsesControllerCreateUrl();
|
|
996
1065
|
const url = `${baseUrl}${path}`;
|
|
997
1066
|
const res = await fetch(url, buildInit("POST", input));
|
|
998
|
-
return
|
|
1067
|
+
return parseEnvelopedResponse(res);
|
|
999
1068
|
},
|
|
1000
1069
|
/**
|
|
1001
|
-
* Partially update a canned response — title,
|
|
1070
|
+
* Partially update a canned response — title, shortcut, category, channel, and/or body.
|
|
1002
1071
|
* Calls PATCH /api/v1/canned-responses/:id.
|
|
1003
1072
|
*/
|
|
1004
1073
|
async update(id, input) {
|
|
1005
1074
|
const path = getCannedResponsesControllerPatchUrl(id);
|
|
1006
1075
|
const url = `${baseUrl}${path}`;
|
|
1007
1076
|
const res = await fetch(url, buildInit("PATCH", input));
|
|
1008
|
-
return
|
|
1077
|
+
return parseEnvelopedResponse(res);
|
|
1009
1078
|
},
|
|
1010
1079
|
/**
|
|
1011
1080
|
* Delete a canned response by id.
|
|
@@ -1018,6 +1087,16 @@ function createCannedResponsesModule(options) {
|
|
|
1018
1087
|
if (!res.ok) {
|
|
1019
1088
|
return parseResponse(res);
|
|
1020
1089
|
}
|
|
1090
|
+
},
|
|
1091
|
+
/**
|
|
1092
|
+
* Duplicate a canned response. The server generates a unique title and
|
|
1093
|
+
* shortcut. Calls POST /api/v1/canned-responses/:id/duplicate.
|
|
1094
|
+
*/
|
|
1095
|
+
async duplicate(id) {
|
|
1096
|
+
const path = getCannedResponsesControllerDuplicateUrl(id);
|
|
1097
|
+
const url = `${baseUrl}${path}`;
|
|
1098
|
+
const res = await fetch(url, buildInit("POST"));
|
|
1099
|
+
return parseEnvelopedResponse(res);
|
|
1021
1100
|
}
|
|
1022
1101
|
};
|
|
1023
1102
|
}
|
|
@@ -1050,7 +1129,7 @@ function createAttachmentsModule(options) {
|
|
|
1050
1129
|
},
|
|
1051
1130
|
body: form
|
|
1052
1131
|
});
|
|
1053
|
-
return
|
|
1132
|
+
return parseEnvelopedResponse(res);
|
|
1054
1133
|
},
|
|
1055
1134
|
/**
|
|
1056
1135
|
* Get a short-lived presigned download URL for a stored attachment.
|
|
@@ -1068,7 +1147,7 @@ function createAttachmentsModule(options) {
|
|
|
1068
1147
|
...options.getHeaders()
|
|
1069
1148
|
}
|
|
1070
1149
|
});
|
|
1071
|
-
return
|
|
1150
|
+
return parseEnvelopedResponse(res);
|
|
1072
1151
|
}
|
|
1073
1152
|
};
|
|
1074
1153
|
}
|
|
@@ -1076,14 +1155,15 @@ function createAttachmentsModule(options) {
|
|
|
1076
1155
|
// src/whatsapp-business-accounts/whatsapp-business-accounts.ts
|
|
1077
1156
|
function createWhatsAppBusinessAccountsModule(options) {
|
|
1078
1157
|
const baseUrl = options.baseUrl;
|
|
1079
|
-
function buildInit(method) {
|
|
1158
|
+
function buildInit(method, body) {
|
|
1080
1159
|
return {
|
|
1081
1160
|
method,
|
|
1082
1161
|
credentials: options.getCredentials(),
|
|
1083
1162
|
headers: {
|
|
1084
1163
|
"Content-Type": "application/json",
|
|
1085
1164
|
...options.getHeaders()
|
|
1086
|
-
}
|
|
1165
|
+
},
|
|
1166
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
1087
1167
|
};
|
|
1088
1168
|
}
|
|
1089
1169
|
return {
|
|
@@ -1118,6 +1198,44 @@ function createWhatsAppBusinessAccountsModule(options) {
|
|
|
1118
1198
|
const url = `${baseUrl}${path}`;
|
|
1119
1199
|
const res = await fetch(url, buildInit("GET"));
|
|
1120
1200
|
return parseEnvelopedResponse(res);
|
|
1201
|
+
},
|
|
1202
|
+
/**
|
|
1203
|
+
* Create a WhatsApp Business Account — writes the secret to the
|
|
1204
|
+
* SecretsProvider and the non-secret row to the DB; returns the
|
|
1205
|
+
* non-secret view (no `secretRef` exposed).
|
|
1206
|
+
* Calls POST /api/v1/tenants/:id/whatsapp-business-accounts.
|
|
1207
|
+
*
|
|
1208
|
+
* @example
|
|
1209
|
+
* const waba = await sdk.whatsappBusinessAccounts.create('ten_acmecorp', {
|
|
1210
|
+
* wabaId: '123456789012345',
|
|
1211
|
+
* name: 'Acme WhatsApp',
|
|
1212
|
+
* secret: { accessToken, appSecret, webhookVerifyToken },
|
|
1213
|
+
* })
|
|
1214
|
+
*/
|
|
1215
|
+
async create(tenantId, body) {
|
|
1216
|
+
const path = getWhatsAppBusinessAccountsControllerCreateUrl(tenantId);
|
|
1217
|
+
const url = `${baseUrl}${path}`;
|
|
1218
|
+
const res = await fetch(url, buildInit("POST", body));
|
|
1219
|
+
return parseEnvelopedResponse(res);
|
|
1220
|
+
},
|
|
1221
|
+
/**
|
|
1222
|
+
* Rename a WhatsApp Business Account (name only — secret material is
|
|
1223
|
+
* immutable through this endpoint).
|
|
1224
|
+
* Calls PATCH /api/v1/tenants/:id/whatsapp-business-accounts/:wabaRowId.
|
|
1225
|
+
*
|
|
1226
|
+
* @example
|
|
1227
|
+
* await sdk.whatsappBusinessAccounts.update('ten_acmecorp', 'waba_row_001', {
|
|
1228
|
+
* name: 'Renamed WhatsApp',
|
|
1229
|
+
* })
|
|
1230
|
+
*/
|
|
1231
|
+
async update(tenantId, wabaRowId, body) {
|
|
1232
|
+
const path = getWhatsAppBusinessAccountsControllerUpdateNameUrl(
|
|
1233
|
+
tenantId,
|
|
1234
|
+
wabaRowId
|
|
1235
|
+
);
|
|
1236
|
+
const url = `${baseUrl}${path}`;
|
|
1237
|
+
const res = await fetch(url, buildInit("PATCH", body));
|
|
1238
|
+
return parseEnvelopedResponse(res);
|
|
1121
1239
|
}
|
|
1122
1240
|
};
|
|
1123
1241
|
}
|