@messagebird/sdk 0.4.2 → 0.6.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 +15 -0
- package/dist/index.d.mts +411 -368
- package/dist/index.mjs +174 -251
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -809,6 +809,7 @@ var BirdAPIError = class extends BirdError {
|
|
|
809
809
|
vendorCode;
|
|
810
810
|
remediation;
|
|
811
811
|
next;
|
|
812
|
+
unmetGates;
|
|
812
813
|
constructor(fields) {
|
|
813
814
|
super(fields.message);
|
|
814
815
|
this.name = "BirdAPIError";
|
|
@@ -822,6 +823,7 @@ var BirdAPIError = class extends BirdError {
|
|
|
822
823
|
this.vendorCode = fields.vendorCode;
|
|
823
824
|
this.remediation = fields.remediation;
|
|
824
825
|
this.next = fields.next;
|
|
826
|
+
this.unmetGates = fields.unmetGates;
|
|
825
827
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
826
828
|
}
|
|
827
829
|
};
|
|
@@ -991,7 +993,8 @@ function mapResponseToError(status, body, headers) {
|
|
|
991
993
|
param: b.param,
|
|
992
994
|
vendorCode: b.vendor_code,
|
|
993
995
|
remediation: b.remediation,
|
|
994
|
-
next: b.next ?? []
|
|
996
|
+
next: b.next ?? [],
|
|
997
|
+
unmetGates: b.unmet_gates ?? []
|
|
995
998
|
};
|
|
996
999
|
switch (fields.type) {
|
|
997
1000
|
case "auth_error": return new BirdAuthError(fields);
|
|
@@ -1261,6 +1264,24 @@ const getEmailMessage = (options) => (options.client ?? client).get({
|
|
|
1261
1264
|
...options
|
|
1262
1265
|
});
|
|
1263
1266
|
/**
|
|
1267
|
+
* Cancel a scheduled message
|
|
1268
|
+
*
|
|
1269
|
+
* Cancels a message that was scheduled with `scheduled_at` before it sends. Only a message that is still scheduled can be canceled; a message that already started sending, was delivered, or was previously canceled returns a conflict error. The message's status becomes `canceled` and an `email.canceled` webhook event fires. Canceling does not return consumed scheduled-send quota.
|
|
1270
|
+
*
|
|
1271
|
+
*/
|
|
1272
|
+
const cancelEmailMessage = (options) => (options.client ?? client).post({
|
|
1273
|
+
security: [{
|
|
1274
|
+
scheme: "bearer",
|
|
1275
|
+
type: "http"
|
|
1276
|
+
}, {
|
|
1277
|
+
in: "cookie",
|
|
1278
|
+
name: "bird_session",
|
|
1279
|
+
type: "apiKey"
|
|
1280
|
+
}],
|
|
1281
|
+
url: "/v1/email/messages/{message_id}/cancel",
|
|
1282
|
+
...options
|
|
1283
|
+
});
|
|
1284
|
+
/**
|
|
1264
1285
|
* List contacts
|
|
1265
1286
|
*
|
|
1266
1287
|
* Returns a paginated list of contacts in the workspace, newest first. Look up a single contact by its exact `email` or `external_id`, or search by email substring with `search`.
|
|
@@ -1496,7 +1517,8 @@ const unarchiveContactProperty = (options) => (options.client ?? client).post({
|
|
|
1496
1517
|
/**
|
|
1497
1518
|
* List audiences
|
|
1498
1519
|
*
|
|
1499
|
-
* Returns a paginated list of audiences in the workspace, newest first.
|
|
1520
|
+
* Returns a paginated list of audiences in the workspace, newest first. Filter to audiences whose name contains a substring with `search`.
|
|
1521
|
+
*
|
|
1500
1522
|
*/
|
|
1501
1523
|
const listAudiences = (options) => (options?.client ?? client).get({
|
|
1502
1524
|
security: [{
|
|
@@ -1782,70 +1804,11 @@ const getSmsTemplate = (options) => (options.client ?? client).get({
|
|
|
1782
1804
|
...options
|
|
1783
1805
|
});
|
|
1784
1806
|
/**
|
|
1785
|
-
* List
|
|
1786
|
-
*
|
|
1787
|
-
* Returns a paginated list of the workspace's email templates, newest first. Filter by category, source, or a case-insensitive search that matches the template's name or description.
|
|
1788
|
-
*
|
|
1789
|
-
*/
|
|
1790
|
-
const listEmailTemplates = (options) => (options?.client ?? client).get({
|
|
1791
|
-
security: [{
|
|
1792
|
-
scheme: "bearer",
|
|
1793
|
-
type: "http"
|
|
1794
|
-
}, {
|
|
1795
|
-
in: "cookie",
|
|
1796
|
-
name: "bird_session",
|
|
1797
|
-
type: "apiKey"
|
|
1798
|
-
}],
|
|
1799
|
-
url: "/v1/email/templates",
|
|
1800
|
-
...options
|
|
1801
|
-
});
|
|
1802
|
-
/**
|
|
1803
|
-
* Create an email template
|
|
1804
|
-
*
|
|
1805
|
-
* Creates a template and its initial editable draft. The body carries the template's name, category, authoring format (`source`), and the draft's content (`subject`, `html`, `text`). A name already used in the workspace returns a conflict.
|
|
1806
|
-
*
|
|
1807
|
-
*/
|
|
1808
|
-
const createEmailTemplate = (options) => (options.client ?? client).post({
|
|
1809
|
-
security: [{
|
|
1810
|
-
scheme: "bearer",
|
|
1811
|
-
type: "http"
|
|
1812
|
-
}, {
|
|
1813
|
-
in: "cookie",
|
|
1814
|
-
name: "bird_session",
|
|
1815
|
-
type: "apiKey"
|
|
1816
|
-
}],
|
|
1817
|
-
url: "/v1/email/templates",
|
|
1818
|
-
...options,
|
|
1819
|
-
headers: {
|
|
1820
|
-
"Content-Type": "application/json",
|
|
1821
|
-
...options.headers
|
|
1822
|
-
}
|
|
1823
|
-
});
|
|
1824
|
-
/**
|
|
1825
|
-
* Delete an email template
|
|
1826
|
-
*
|
|
1827
|
-
* Deletes the template and all its versions. The name becomes available for reuse within the workspace.
|
|
1828
|
-
*
|
|
1829
|
-
*/
|
|
1830
|
-
const deleteEmailTemplate = (options) => (options.client ?? client).delete({
|
|
1831
|
-
security: [{
|
|
1832
|
-
scheme: "bearer",
|
|
1833
|
-
type: "http"
|
|
1834
|
-
}, {
|
|
1835
|
-
in: "cookie",
|
|
1836
|
-
name: "bird_session",
|
|
1837
|
-
type: "apiKey"
|
|
1838
|
-
}],
|
|
1839
|
-
url: "/v1/email/templates/{template_id}",
|
|
1840
|
-
...options
|
|
1841
|
-
});
|
|
1842
|
-
/**
|
|
1843
|
-
* Get an email template
|
|
1844
|
-
*
|
|
1845
|
-
* Returns a single email template with its current draft content (subject, HTML, and plain text), the draft revision, and its draft and published version ids.
|
|
1807
|
+
* List WhatsApp messages
|
|
1846
1808
|
*
|
|
1809
|
+
* Returns a paginated list of WhatsApp messages in the workspace, newest first.
|
|
1847
1810
|
*/
|
|
1848
|
-
const
|
|
1811
|
+
const listWhatsAppMessages = (options) => (options?.client ?? client).get({
|
|
1849
1812
|
security: [{
|
|
1850
1813
|
scheme: "bearer",
|
|
1851
1814
|
type: "http"
|
|
@@ -1854,16 +1817,15 @@ const getEmailTemplate = (options) => (options.client ?? client).get({
|
|
|
1854
1817
|
name: "bird_session",
|
|
1855
1818
|
type: "apiKey"
|
|
1856
1819
|
}],
|
|
1857
|
-
url: "/v1/
|
|
1820
|
+
url: "/v1/whatsapp/messages",
|
|
1858
1821
|
...options
|
|
1859
1822
|
});
|
|
1860
1823
|
/**
|
|
1861
|
-
*
|
|
1862
|
-
*
|
|
1863
|
-
* Updates a template's metadata and its draft content. Only the fields you send are changed. Send the draft `revision` you last read; if it is stale (someone else edited the draft first) the request returns a conflict so you can reload and retry.
|
|
1824
|
+
* Send a message
|
|
1864
1825
|
*
|
|
1826
|
+
* Sends a template message. Bird selects the sender number from the template's category.
|
|
1865
1827
|
*/
|
|
1866
|
-
const
|
|
1828
|
+
const sendWhatsAppMessage = (options) => (options.client ?? client).post({
|
|
1867
1829
|
security: [{
|
|
1868
1830
|
scheme: "bearer",
|
|
1869
1831
|
type: "http"
|
|
@@ -1872,7 +1834,7 @@ const updateEmailTemplate = (options) => (options.client ?? client).patch({
|
|
|
1872
1834
|
name: "bird_session",
|
|
1873
1835
|
type: "apiKey"
|
|
1874
1836
|
}],
|
|
1875
|
-
url: "/v1/
|
|
1837
|
+
url: "/v1/whatsapp/messages",
|
|
1876
1838
|
...options,
|
|
1877
1839
|
headers: {
|
|
1878
1840
|
"Content-Type": "application/json",
|
|
@@ -1880,12 +1842,11 @@ const updateEmailTemplate = (options) => (options.client ?? client).patch({
|
|
|
1880
1842
|
}
|
|
1881
1843
|
});
|
|
1882
1844
|
/**
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
* Returns every version of the template — the current draft plus all published versions — newest first.
|
|
1845
|
+
* Get a WhatsApp message
|
|
1886
1846
|
*
|
|
1847
|
+
* Returns a single WhatsApp message with its current delivery status and failure detail if applicable.
|
|
1887
1848
|
*/
|
|
1888
|
-
const
|
|
1849
|
+
const getWhatsAppMessage = (options) => (options.client ?? client).get({
|
|
1889
1850
|
security: [{
|
|
1890
1851
|
scheme: "bearer",
|
|
1891
1852
|
type: "http"
|
|
@@ -1894,15 +1855,15 @@ const listEmailTemplateVersions = (options) => (options.client ?? client).get({
|
|
|
1894
1855
|
name: "bird_session",
|
|
1895
1856
|
type: "apiKey"
|
|
1896
1857
|
}],
|
|
1897
|
-
url: "/v1/
|
|
1858
|
+
url: "/v1/whatsapp/messages/{message_id}",
|
|
1898
1859
|
...options
|
|
1899
1860
|
});
|
|
1900
1861
|
/**
|
|
1901
|
-
*
|
|
1862
|
+
* List events for a WhatsApp message
|
|
1902
1863
|
*
|
|
1903
|
-
* Returns a
|
|
1864
|
+
* Returns the lifecycle event timeline for a WhatsApp message, in chronological order.
|
|
1904
1865
|
*/
|
|
1905
|
-
const
|
|
1866
|
+
const listWhatsAppMessageEvents = (options) => (options.client ?? client).get({
|
|
1906
1867
|
security: [{
|
|
1907
1868
|
scheme: "bearer",
|
|
1908
1869
|
type: "http"
|
|
@@ -1911,16 +1872,15 @@ const getEmailTemplateVersion = (options) => (options.client ?? client).get({
|
|
|
1911
1872
|
name: "bird_session",
|
|
1912
1873
|
type: "apiKey"
|
|
1913
1874
|
}],
|
|
1914
|
-
url: "/v1/
|
|
1875
|
+
url: "/v1/whatsapp/messages/{message_id}/events",
|
|
1915
1876
|
...options
|
|
1916
1877
|
});
|
|
1917
1878
|
/**
|
|
1918
|
-
*
|
|
1919
|
-
*
|
|
1920
|
-
* Publishes the template's current draft as a new immutable, numbered version and makes it the live version used by sends. The draft remains editable for future changes. The draft must have a subject and a body; an empty draft is rejected.
|
|
1879
|
+
* List available message templates
|
|
1921
1880
|
*
|
|
1881
|
+
* Returns the message templates available to this workspace.
|
|
1922
1882
|
*/
|
|
1923
|
-
const
|
|
1883
|
+
const listWhatsAppTemplates = (options) => (options?.client ?? client).get({
|
|
1924
1884
|
security: [{
|
|
1925
1885
|
scheme: "bearer",
|
|
1926
1886
|
type: "http"
|
|
@@ -1929,7 +1889,7 @@ const publishEmailTemplate = (options) => (options.client ?? client).post({
|
|
|
1929
1889
|
name: "bird_session",
|
|
1930
1890
|
type: "apiKey"
|
|
1931
1891
|
}],
|
|
1932
|
-
url: "/v1/
|
|
1892
|
+
url: "/v1/whatsapp/templates",
|
|
1933
1893
|
...options
|
|
1934
1894
|
});
|
|
1935
1895
|
//#endregion
|
|
@@ -2106,6 +2066,23 @@ var EmailResource = class extends Resource {
|
|
|
2106
2066
|
}));
|
|
2107
2067
|
}
|
|
2108
2068
|
/**
|
|
2069
|
+
* Cancel a message scheduled with `scheduled_at` before it sends. Only a
|
|
2070
|
+
* message that is still scheduled can be canceled; one that already started
|
|
2071
|
+
* sending — or was previously canceled — rejects with a conflict error.
|
|
2072
|
+
* Canceling does not return consumed scheduled-send quota.
|
|
2073
|
+
*
|
|
2074
|
+
* @example
|
|
2075
|
+
* await bird.email.cancel("em_abc123");
|
|
2076
|
+
*/
|
|
2077
|
+
cancel(messageId, options) {
|
|
2078
|
+
return this.call("POST", options, ({ signal, headers }) => cancelEmailMessage({
|
|
2079
|
+
client: this.client,
|
|
2080
|
+
path: { message_id: messageId },
|
|
2081
|
+
headers,
|
|
2082
|
+
signal
|
|
2083
|
+
}));
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2109
2086
|
* List messages, newest first. `await` resolves the first page; `for await`
|
|
2110
2087
|
* walks every message across all pages.
|
|
2111
2088
|
*
|
|
@@ -2487,166 +2464,6 @@ var ContactsResource = class extends Resource {
|
|
|
2487
2464
|
}
|
|
2488
2465
|
};
|
|
2489
2466
|
//#endregion
|
|
2490
|
-
//#region src/resources/emailTemplates.ts
|
|
2491
|
-
var EmailTemplatesResource = class extends Resource {
|
|
2492
|
-
/**
|
|
2493
|
-
* Create a template and its initial editable draft. Pick the authoring format
|
|
2494
|
-
* with `source` (`liquid`, `handlebars`, or `html`); the name must be unique
|
|
2495
|
-
* in the workspace or the call throws a `BirdConflictError`.
|
|
2496
|
-
*
|
|
2497
|
-
* @example Create a template
|
|
2498
|
-
* const tpl = await bird.emailTemplates.create({
|
|
2499
|
-
* name: "welcome-email",
|
|
2500
|
-
* description: "Welcome",
|
|
2501
|
-
* category: "transactional",
|
|
2502
|
-
* source: "handlebars",
|
|
2503
|
-
* subject: "Welcome, {{ first_name }}!",
|
|
2504
|
-
* html: "<h1>Hi {{ first_name }}</h1>",
|
|
2505
|
-
* });
|
|
2506
|
-
* console.log(tpl.id, tpl.revision); // "emt_…", 0
|
|
2507
|
-
*/
|
|
2508
|
-
create(params, options) {
|
|
2509
|
-
return this.call("POST", options, ({ signal, headers }) => createEmailTemplate({
|
|
2510
|
-
client: this.client,
|
|
2511
|
-
body: params,
|
|
2512
|
-
headers,
|
|
2513
|
-
signal
|
|
2514
|
-
}));
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* List the workspace's templates, newest first. `await` resolves the first
|
|
2518
|
-
* page; `for await` walks every template across all pages. Filter by
|
|
2519
|
-
* `category`, `source`, or a case-insensitive `name` prefix.
|
|
2520
|
-
*
|
|
2521
|
-
* @example Iterate every template, or take one page
|
|
2522
|
-
* for await (const tpl of bird.emailTemplates.list({ category: "transactional" })) {
|
|
2523
|
-
* console.log(tpl.id, tpl.name);
|
|
2524
|
-
* }
|
|
2525
|
-
* const page = await bird.emailTemplates.list({ limit: 50 }); // page.data, page.next_cursor
|
|
2526
|
-
*/
|
|
2527
|
-
list(query, options) {
|
|
2528
|
-
return this.paginated("GET", options, ({ signal, headers }, cursor) => listEmailTemplates({
|
|
2529
|
-
client: this.client,
|
|
2530
|
-
query: {
|
|
2531
|
-
...query,
|
|
2532
|
-
starting_after: cursor ?? query?.starting_after
|
|
2533
|
-
},
|
|
2534
|
-
headers,
|
|
2535
|
-
signal
|
|
2536
|
-
}));
|
|
2537
|
-
}
|
|
2538
|
-
/**
|
|
2539
|
-
* Fetch a template with its current draft content (subject, HTML, text), the
|
|
2540
|
-
* draft `revision`, and its draft/published version ids.
|
|
2541
|
-
*
|
|
2542
|
-
* @example
|
|
2543
|
-
* const tpl = await bird.emailTemplates.get("emt_abc123");
|
|
2544
|
-
* tpl.subject;
|
|
2545
|
-
* tpl.published_version_id; // null until first publish
|
|
2546
|
-
*/
|
|
2547
|
-
get(templateId, options) {
|
|
2548
|
-
return this.call("GET", options, ({ signal, headers }) => getEmailTemplate({
|
|
2549
|
-
client: this.client,
|
|
2550
|
-
path: { template_id: templateId },
|
|
2551
|
-
headers,
|
|
2552
|
-
signal
|
|
2553
|
-
}));
|
|
2554
|
-
}
|
|
2555
|
-
/**
|
|
2556
|
-
* Update a template's metadata and draft content. Only the fields you send
|
|
2557
|
-
* change. Pass the draft `revision` you last read; if another edit landed
|
|
2558
|
-
* first the call throws a `BirdConflictError` — reload and retry.
|
|
2559
|
-
*
|
|
2560
|
-
* @example Edit the draft, guarded by the revision you read
|
|
2561
|
-
* const tpl = await bird.emailTemplates.get("emt_abc123");
|
|
2562
|
-
* const updated = await bird.emailTemplates.update("emt_abc123", {
|
|
2563
|
-
* revision: tpl.revision,
|
|
2564
|
-
* subject: "Welcome aboard, {{ first_name }}!",
|
|
2565
|
-
* });
|
|
2566
|
-
*/
|
|
2567
|
-
update(templateId, params, options) {
|
|
2568
|
-
return this.call("PATCH", options, ({ signal, headers }) => updateEmailTemplate({
|
|
2569
|
-
client: this.client,
|
|
2570
|
-
path: { template_id: templateId },
|
|
2571
|
-
body: params,
|
|
2572
|
-
headers,
|
|
2573
|
-
signal
|
|
2574
|
-
}));
|
|
2575
|
-
}
|
|
2576
|
-
/**
|
|
2577
|
-
* Delete a template and all its versions. The name becomes available for
|
|
2578
|
-
* reuse in the workspace.
|
|
2579
|
-
*
|
|
2580
|
-
* @example
|
|
2581
|
-
* await bird.emailTemplates.delete("emt_abc123");
|
|
2582
|
-
*/
|
|
2583
|
-
delete(templateId, options) {
|
|
2584
|
-
return this.call("DELETE", options, ({ signal, headers }) => deleteEmailTemplate({
|
|
2585
|
-
client: this.client,
|
|
2586
|
-
path: { template_id: templateId },
|
|
2587
|
-
headers,
|
|
2588
|
-
signal
|
|
2589
|
-
}));
|
|
2590
|
-
}
|
|
2591
|
-
/**
|
|
2592
|
-
* Publish the current draft as a new immutable, numbered version and make it
|
|
2593
|
-
* the live version used by sends. The draft stays editable. The draft must
|
|
2594
|
-
* have a subject and a body, or the call throws.
|
|
2595
|
-
*
|
|
2596
|
-
* @example Publish, then send by template
|
|
2597
|
-
* const version = await bird.emailTemplates.publish("emt_abc123");
|
|
2598
|
-
* console.log(version.version_number); // 1, 2, 3…
|
|
2599
|
-
* await bird.email.send({
|
|
2600
|
-
* from: "hello@acme.com",
|
|
2601
|
-
* to: ["alice@example.com"],
|
|
2602
|
-
* template: { id: "emt_abc123", parameters: { first_name: "Alice" } },
|
|
2603
|
-
* });
|
|
2604
|
-
*/
|
|
2605
|
-
publish(templateId, options) {
|
|
2606
|
-
return this.call("POST", options, ({ signal, headers }) => publishEmailTemplate({
|
|
2607
|
-
client: this.client,
|
|
2608
|
-
path: { template_id: templateId },
|
|
2609
|
-
headers,
|
|
2610
|
-
signal
|
|
2611
|
-
}));
|
|
2612
|
-
}
|
|
2613
|
-
/**
|
|
2614
|
-
* List every version of a template — the current draft plus all published
|
|
2615
|
-
* versions — newest first. Returns the full set in one response (`.data`);
|
|
2616
|
-
* this list is not paginated.
|
|
2617
|
-
*
|
|
2618
|
-
* @example
|
|
2619
|
-
* const { data } = await bird.emailTemplates.listVersions("emt_abc123");
|
|
2620
|
-
* for (const v of data) console.log(v.version_number, v.status);
|
|
2621
|
-
*/
|
|
2622
|
-
listVersions(templateId, options) {
|
|
2623
|
-
return this.call("GET", options, ({ signal, headers }) => listEmailTemplateVersions({
|
|
2624
|
-
client: this.client,
|
|
2625
|
-
path: { template_id: templateId },
|
|
2626
|
-
headers,
|
|
2627
|
-
signal
|
|
2628
|
-
}));
|
|
2629
|
-
}
|
|
2630
|
-
/**
|
|
2631
|
-
* Fetch a single version of a template.
|
|
2632
|
-
*
|
|
2633
|
-
* @example
|
|
2634
|
-
* const version = await bird.emailTemplates.getVersion("emt_abc123", "emv_def456");
|
|
2635
|
-
* version.status; // "draft" | "published"
|
|
2636
|
-
*/
|
|
2637
|
-
getVersion(templateId, versionId, options) {
|
|
2638
|
-
return this.call("GET", options, ({ signal, headers }) => getEmailTemplateVersion({
|
|
2639
|
-
client: this.client,
|
|
2640
|
-
path: {
|
|
2641
|
-
template_id: templateId,
|
|
2642
|
-
version_id: versionId
|
|
2643
|
-
},
|
|
2644
|
-
headers,
|
|
2645
|
-
signal
|
|
2646
|
-
}));
|
|
2647
|
-
}
|
|
2648
|
-
};
|
|
2649
|
-
//#endregion
|
|
2650
2467
|
//#region src/resources/sms.ts
|
|
2651
2468
|
var SmsResource = class extends Resource {
|
|
2652
2469
|
/**
|
|
@@ -2771,6 +2588,111 @@ var SmsTemplatesResource = class extends Resource {
|
|
|
2771
2588
|
}
|
|
2772
2589
|
};
|
|
2773
2590
|
//#endregion
|
|
2591
|
+
//#region src/resources/whatsapp.ts
|
|
2592
|
+
var WhatsappResource = class extends Resource {
|
|
2593
|
+
/**
|
|
2594
|
+
* Send a template message. Bird selects the sender number from the
|
|
2595
|
+
* template's category, so there is no sender field on the request. The
|
|
2596
|
+
* result is `accepted`, not yet delivered — read it back with `get` to
|
|
2597
|
+
* confirm.
|
|
2598
|
+
*
|
|
2599
|
+
* @example
|
|
2600
|
+
* const msg = await bird.whatsapp.send({
|
|
2601
|
+
* to: "+15551234567",
|
|
2602
|
+
* template: {
|
|
2603
|
+
* name: "bird_otp",
|
|
2604
|
+
* components: [
|
|
2605
|
+
* { type: "body", parameters: [{ type: "text", text: "123456" }] },
|
|
2606
|
+
* ],
|
|
2607
|
+
* },
|
|
2608
|
+
* });
|
|
2609
|
+
* console.log(msg.id, msg.status);
|
|
2610
|
+
*/
|
|
2611
|
+
send(params, options) {
|
|
2612
|
+
return this.call("POST", options, ({ signal, headers }) => sendWhatsAppMessage({
|
|
2613
|
+
client: this.client,
|
|
2614
|
+
body: params,
|
|
2615
|
+
headers,
|
|
2616
|
+
signal
|
|
2617
|
+
}));
|
|
2618
|
+
}
|
|
2619
|
+
/**
|
|
2620
|
+
* Fetch a single WhatsApp message: its current delivery status and failure
|
|
2621
|
+
* detail if it failed.
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* const msg = await bird.whatsapp.get("wa_abc123");
|
|
2625
|
+
* msg.status; // "accepted" | "delivered" | …
|
|
2626
|
+
*/
|
|
2627
|
+
get(messageId, options) {
|
|
2628
|
+
return this.call("GET", options, ({ signal, headers }) => getWhatsAppMessage({
|
|
2629
|
+
client: this.client,
|
|
2630
|
+
path: { message_id: messageId },
|
|
2631
|
+
headers,
|
|
2632
|
+
signal
|
|
2633
|
+
}));
|
|
2634
|
+
}
|
|
2635
|
+
/**
|
|
2636
|
+
* List WhatsApp messages, newest first. `await` resolves the first page;
|
|
2637
|
+
* `for await` walks every message across all pages. Filter by status,
|
|
2638
|
+
* recipient phone number, or business-scoped user ID.
|
|
2639
|
+
*
|
|
2640
|
+
* @example
|
|
2641
|
+
* for await (const msg of bird.whatsapp.list({ status: ["delivered"] })) {
|
|
2642
|
+
* console.log(msg.id, msg.status);
|
|
2643
|
+
* }
|
|
2644
|
+
*/
|
|
2645
|
+
list(query, options) {
|
|
2646
|
+
return this.paginated("GET", options, ({ signal, headers }, cursor) => listWhatsAppMessages({
|
|
2647
|
+
client: this.client,
|
|
2648
|
+
query: {
|
|
2649
|
+
...query,
|
|
2650
|
+
starting_after: cursor ?? query?.starting_after
|
|
2651
|
+
},
|
|
2652
|
+
headers,
|
|
2653
|
+
signal
|
|
2654
|
+
}));
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* List a WhatsApp message's lifecycle event timeline, in chronological
|
|
2658
|
+
* order. The timeline is bounded and returned in full — this list is not
|
|
2659
|
+
* paginated.
|
|
2660
|
+
*
|
|
2661
|
+
* @example
|
|
2662
|
+
* const { data } = await bird.whatsapp.listEvents("wa_abc123");
|
|
2663
|
+
* for (const event of data) console.log(event.type, event.occurred_at);
|
|
2664
|
+
*/
|
|
2665
|
+
listEvents(messageId, query, options) {
|
|
2666
|
+
return this.call("GET", options, ({ signal, headers }) => listWhatsAppMessageEvents({
|
|
2667
|
+
client: this.client,
|
|
2668
|
+
path: { message_id: messageId },
|
|
2669
|
+
query,
|
|
2670
|
+
headers,
|
|
2671
|
+
signal
|
|
2672
|
+
}));
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
//#endregion
|
|
2676
|
+
//#region src/resources/whatsappTemplates.ts
|
|
2677
|
+
var WhatsappTemplatesResource = class extends Resource {
|
|
2678
|
+
/**
|
|
2679
|
+
* List the WhatsApp message templates available to the workspace — Meta's
|
|
2680
|
+
* approved templates for this business account. The catalogue is small and
|
|
2681
|
+
* returned in full (`.data`); this list is not paginated.
|
|
2682
|
+
*
|
|
2683
|
+
* @example
|
|
2684
|
+
* const { data } = await bird.whatsappTemplates.list();
|
|
2685
|
+
* for (const tpl of data) console.log(tpl.name, tpl.status);
|
|
2686
|
+
*/
|
|
2687
|
+
list(options) {
|
|
2688
|
+
return this.call("GET", options, ({ signal, headers }) => listWhatsAppTemplates({
|
|
2689
|
+
client: this.client,
|
|
2690
|
+
headers,
|
|
2691
|
+
signal
|
|
2692
|
+
}));
|
|
2693
|
+
}
|
|
2694
|
+
};
|
|
2695
|
+
//#endregion
|
|
2774
2696
|
//#region src/resources/webhooks.ts
|
|
2775
2697
|
var WebhooksResource = class {
|
|
2776
2698
|
#secret;
|
|
@@ -2887,12 +2809,14 @@ var BirdClient = class {
|
|
|
2887
2809
|
#headers;
|
|
2888
2810
|
/** The email channel — `bird.email.send(...)`, `.get(...)`, `.list(...)`. */
|
|
2889
2811
|
email;
|
|
2890
|
-
/** Email templates — `bird.emailTemplates.create(...)`, `.list(...)`, `.publish(...)`, … */
|
|
2891
|
-
emailTemplates;
|
|
2892
2812
|
/** The SMS channel — `bird.sms.send(...)`, `.get(...)`, `.list(...)`. */
|
|
2893
2813
|
sms;
|
|
2894
2814
|
/** SMS templates — `bird.smsTemplates.list(...)`, `.get(...)`. */
|
|
2895
2815
|
smsTemplates;
|
|
2816
|
+
/** The WhatsApp channel — `bird.whatsapp.send(...)`, `.get(...)`, `.list(...)`, `.listEvents(...)`. */
|
|
2817
|
+
whatsapp;
|
|
2818
|
+
/** WhatsApp templates — `bird.whatsappTemplates.list(...)`. */
|
|
2819
|
+
whatsappTemplates;
|
|
2896
2820
|
/** Contacts — `bird.contacts.create(...)`, `.list(...)`, `.get(...)`, `.batch(...)`, … */
|
|
2897
2821
|
contacts;
|
|
2898
2822
|
/** Audiences — `bird.audiences.create(...)`, `.list(...)`, `.addContacts(...)`, … */
|
|
@@ -2908,9 +2832,9 @@ var BirdClient = class {
|
|
|
2908
2832
|
this.#headers = {
|
|
2909
2833
|
...opts.defaultHeaders,
|
|
2910
2834
|
Authorization: `Bearer ${opts.apiKey}`,
|
|
2911
|
-
"User-Agent": `bird-sdk-js/0.
|
|
2835
|
+
"User-Agent": `bird-sdk-js/0.6.0`,
|
|
2912
2836
|
"Bird-Surface": "sdk-js",
|
|
2913
|
-
"Bird-Version": "0.
|
|
2837
|
+
"Bird-Version": "0.6.0"
|
|
2914
2838
|
};
|
|
2915
2839
|
const caller = detectCaller();
|
|
2916
2840
|
if (caller) this.#headers["Bird-Caller"] = caller;
|
|
@@ -2924,9 +2848,10 @@ var BirdClient = class {
|
|
|
2924
2848
|
maxRetries: opts.maxRetries ?? DEFAULT_MAX_RETRIES
|
|
2925
2849
|
});
|
|
2926
2850
|
this.email = new EmailResource(this.core, this.#client, opts.email);
|
|
2927
|
-
this.emailTemplates = new EmailTemplatesResource(this.core, this.#client);
|
|
2928
2851
|
this.sms = new SmsResource(this.core, this.#client);
|
|
2929
2852
|
this.smsTemplates = new SmsTemplatesResource(this.core, this.#client);
|
|
2853
|
+
this.whatsapp = new WhatsappResource(this.core, this.#client);
|
|
2854
|
+
this.whatsappTemplates = new WhatsappTemplatesResource(this.core, this.#client);
|
|
2930
2855
|
this.contacts = new ContactsResource(this.core, this.#client);
|
|
2931
2856
|
this.audiences = new AudiencesResource(this.core, this.#client);
|
|
2932
2857
|
this.contactProperties = new ContactPropertiesResource(this.core, this.#client);
|
|
@@ -3003,8 +2928,6 @@ const WebhookEventType = {
|
|
|
3003
2928
|
EmailMailboxMessageDelivered: "email_mailbox.message_delivered",
|
|
3004
2929
|
EmailMailboxMessageFailed: "email_mailbox.message_failed",
|
|
3005
2930
|
EmailMailboxMessageReceived: "email_mailbox.message_received",
|
|
3006
|
-
EmailMailboxMessageReceivedBlocked: "email_mailbox.message_received_blocked",
|
|
3007
|
-
EmailMailboxMessageReceivedUnauthenticated: "email_mailbox.message_received_unauthenticated",
|
|
3008
2931
|
EmailMailboxMessageSent: "email_mailbox.message_sent",
|
|
3009
2932
|
EmailMailboxSuspended: "email_mailbox.suspended",
|
|
3010
2933
|
EmailMailboxThreadCreated: "email_mailbox.thread_created",
|