@messagebird/sdk 0.5.0 → 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 +438 -73
- package/dist/index.mjs +202 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1803,6 +1803,95 @@ const getSmsTemplate = (options) => (options.client ?? client).get({
|
|
|
1803
1803
|
url: "/v1/sms/templates/{template_ref}",
|
|
1804
1804
|
...options
|
|
1805
1805
|
});
|
|
1806
|
+
/**
|
|
1807
|
+
* List WhatsApp messages
|
|
1808
|
+
*
|
|
1809
|
+
* Returns a paginated list of WhatsApp messages in the workspace, newest first.
|
|
1810
|
+
*/
|
|
1811
|
+
const listWhatsAppMessages = (options) => (options?.client ?? client).get({
|
|
1812
|
+
security: [{
|
|
1813
|
+
scheme: "bearer",
|
|
1814
|
+
type: "http"
|
|
1815
|
+
}, {
|
|
1816
|
+
in: "cookie",
|
|
1817
|
+
name: "bird_session",
|
|
1818
|
+
type: "apiKey"
|
|
1819
|
+
}],
|
|
1820
|
+
url: "/v1/whatsapp/messages",
|
|
1821
|
+
...options
|
|
1822
|
+
});
|
|
1823
|
+
/**
|
|
1824
|
+
* Send a message
|
|
1825
|
+
*
|
|
1826
|
+
* Sends a template message. Bird selects the sender number from the template's category.
|
|
1827
|
+
*/
|
|
1828
|
+
const sendWhatsAppMessage = (options) => (options.client ?? client).post({
|
|
1829
|
+
security: [{
|
|
1830
|
+
scheme: "bearer",
|
|
1831
|
+
type: "http"
|
|
1832
|
+
}, {
|
|
1833
|
+
in: "cookie",
|
|
1834
|
+
name: "bird_session",
|
|
1835
|
+
type: "apiKey"
|
|
1836
|
+
}],
|
|
1837
|
+
url: "/v1/whatsapp/messages",
|
|
1838
|
+
...options,
|
|
1839
|
+
headers: {
|
|
1840
|
+
"Content-Type": "application/json",
|
|
1841
|
+
...options.headers
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
/**
|
|
1845
|
+
* Get a WhatsApp message
|
|
1846
|
+
*
|
|
1847
|
+
* Returns a single WhatsApp message with its current delivery status and failure detail if applicable.
|
|
1848
|
+
*/
|
|
1849
|
+
const getWhatsAppMessage = (options) => (options.client ?? client).get({
|
|
1850
|
+
security: [{
|
|
1851
|
+
scheme: "bearer",
|
|
1852
|
+
type: "http"
|
|
1853
|
+
}, {
|
|
1854
|
+
in: "cookie",
|
|
1855
|
+
name: "bird_session",
|
|
1856
|
+
type: "apiKey"
|
|
1857
|
+
}],
|
|
1858
|
+
url: "/v1/whatsapp/messages/{message_id}",
|
|
1859
|
+
...options
|
|
1860
|
+
});
|
|
1861
|
+
/**
|
|
1862
|
+
* List events for a WhatsApp message
|
|
1863
|
+
*
|
|
1864
|
+
* Returns the lifecycle event timeline for a WhatsApp message, in chronological order.
|
|
1865
|
+
*/
|
|
1866
|
+
const listWhatsAppMessageEvents = (options) => (options.client ?? client).get({
|
|
1867
|
+
security: [{
|
|
1868
|
+
scheme: "bearer",
|
|
1869
|
+
type: "http"
|
|
1870
|
+
}, {
|
|
1871
|
+
in: "cookie",
|
|
1872
|
+
name: "bird_session",
|
|
1873
|
+
type: "apiKey"
|
|
1874
|
+
}],
|
|
1875
|
+
url: "/v1/whatsapp/messages/{message_id}/events",
|
|
1876
|
+
...options
|
|
1877
|
+
});
|
|
1878
|
+
/**
|
|
1879
|
+
* List available message templates
|
|
1880
|
+
*
|
|
1881
|
+
* Returns the message templates available to this workspace.
|
|
1882
|
+
*/
|
|
1883
|
+
const listWhatsAppTemplates = (options) => (options?.client ?? client).get({
|
|
1884
|
+
security: [{
|
|
1885
|
+
scheme: "bearer",
|
|
1886
|
+
type: "http"
|
|
1887
|
+
}, {
|
|
1888
|
+
in: "cookie",
|
|
1889
|
+
name: "bird_session",
|
|
1890
|
+
type: "apiKey"
|
|
1891
|
+
}],
|
|
1892
|
+
url: "/v1/whatsapp/templates",
|
|
1893
|
+
...options
|
|
1894
|
+
});
|
|
1806
1895
|
//#endregion
|
|
1807
1896
|
//#region src/resources/base.ts
|
|
1808
1897
|
var Resource = class {
|
|
@@ -2499,6 +2588,111 @@ var SmsTemplatesResource = class extends Resource {
|
|
|
2499
2588
|
}
|
|
2500
2589
|
};
|
|
2501
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
|
|
2502
2696
|
//#region src/resources/webhooks.ts
|
|
2503
2697
|
var WebhooksResource = class {
|
|
2504
2698
|
#secret;
|
|
@@ -2619,6 +2813,10 @@ var BirdClient = class {
|
|
|
2619
2813
|
sms;
|
|
2620
2814
|
/** SMS templates — `bird.smsTemplates.list(...)`, `.get(...)`. */
|
|
2621
2815
|
smsTemplates;
|
|
2816
|
+
/** The WhatsApp channel — `bird.whatsapp.send(...)`, `.get(...)`, `.list(...)`, `.listEvents(...)`. */
|
|
2817
|
+
whatsapp;
|
|
2818
|
+
/** WhatsApp templates — `bird.whatsappTemplates.list(...)`. */
|
|
2819
|
+
whatsappTemplates;
|
|
2622
2820
|
/** Contacts — `bird.contacts.create(...)`, `.list(...)`, `.get(...)`, `.batch(...)`, … */
|
|
2623
2821
|
contacts;
|
|
2624
2822
|
/** Audiences — `bird.audiences.create(...)`, `.list(...)`, `.addContacts(...)`, … */
|
|
@@ -2634,9 +2832,9 @@ var BirdClient = class {
|
|
|
2634
2832
|
this.#headers = {
|
|
2635
2833
|
...opts.defaultHeaders,
|
|
2636
2834
|
Authorization: `Bearer ${opts.apiKey}`,
|
|
2637
|
-
"User-Agent": `bird-sdk-js/0.
|
|
2835
|
+
"User-Agent": `bird-sdk-js/0.6.0`,
|
|
2638
2836
|
"Bird-Surface": "sdk-js",
|
|
2639
|
-
"Bird-Version": "0.
|
|
2837
|
+
"Bird-Version": "0.6.0"
|
|
2640
2838
|
};
|
|
2641
2839
|
const caller = detectCaller();
|
|
2642
2840
|
if (caller) this.#headers["Bird-Caller"] = caller;
|
|
@@ -2652,6 +2850,8 @@ var BirdClient = class {
|
|
|
2652
2850
|
this.email = new EmailResource(this.core, this.#client, opts.email);
|
|
2653
2851
|
this.sms = new SmsResource(this.core, this.#client);
|
|
2654
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);
|
|
2655
2855
|
this.contacts = new ContactsResource(this.core, this.#client);
|
|
2656
2856
|
this.audiences = new AudiencesResource(this.core, this.#client);
|
|
2657
2857
|
this.contactProperties = new ContactPropertiesResource(this.core, this.#client);
|
|
@@ -2728,8 +2928,6 @@ const WebhookEventType = {
|
|
|
2728
2928
|
EmailMailboxMessageDelivered: "email_mailbox.message_delivered",
|
|
2729
2929
|
EmailMailboxMessageFailed: "email_mailbox.message_failed",
|
|
2730
2930
|
EmailMailboxMessageReceived: "email_mailbox.message_received",
|
|
2731
|
-
EmailMailboxMessageReceivedBlocked: "email_mailbox.message_received_blocked",
|
|
2732
|
-
EmailMailboxMessageReceivedUnauthenticated: "email_mailbox.message_received_unauthenticated",
|
|
2733
2931
|
EmailMailboxMessageSent: "email_mailbox.message_sent",
|
|
2734
2932
|
EmailMailboxSuspended: "email_mailbox.suspended",
|
|
2735
2933
|
EmailMailboxThreadCreated: "email_mailbox.thread_created",
|