@messagebird/sdk 0.5.0 → 0.7.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 +674 -94
- package/dist/index.mjs +301 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1803,6 +1803,139 @@ const getSmsTemplate = (options) => (options.client ?? client).get({
|
|
|
1803
1803
|
url: "/v1/sms/templates/{template_ref}",
|
|
1804
1804
|
...options
|
|
1805
1805
|
});
|
|
1806
|
+
/**
|
|
1807
|
+
* Create a verification
|
|
1808
|
+
*
|
|
1809
|
+
* Creates a verification for a recipient and sends them a one-time passcode. Provide a recipient in `to` — an email address (verified over email), a phone number (verified over SMS), or both. If a verification is already in progress for the same recipient, that one is reused and its passcode is re-sent once the resend cooldown has elapsed, rather than starting a second verification. The response includes the verification's current state; the passcode itself is never returned. Submit the passcode the recipient enters with the check endpoint.
|
|
1810
|
+
*
|
|
1811
|
+
*/
|
|
1812
|
+
const createVerification = (options) => (options.client ?? client).post({
|
|
1813
|
+
security: [{
|
|
1814
|
+
scheme: "bearer",
|
|
1815
|
+
type: "http"
|
|
1816
|
+
}, {
|
|
1817
|
+
in: "cookie",
|
|
1818
|
+
name: "bird_session",
|
|
1819
|
+
type: "apiKey"
|
|
1820
|
+
}],
|
|
1821
|
+
url: "/v1/verify/verifications",
|
|
1822
|
+
...options,
|
|
1823
|
+
headers: {
|
|
1824
|
+
"Content-Type": "application/json",
|
|
1825
|
+
...options.headers
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
/**
|
|
1829
|
+
* Check a verification passcode
|
|
1830
|
+
*
|
|
1831
|
+
* Checks a passcode for a recipient and returns the outcome together with the verification's current state. Identify the verification by the same `to` recipient used to create it — you do not need to store a verification id. A wrong, expired, or already-used passcode is reported in the response body, with `success` set to `false` and a `reason` such as `incorrect_code` or `expired`, rather than as an HTTP error; only a missing verification, malformed input, or rate limiting return an error status.
|
|
1832
|
+
*
|
|
1833
|
+
*/
|
|
1834
|
+
const createVerificationCheck = (options) => (options.client ?? client).post({
|
|
1835
|
+
security: [{
|
|
1836
|
+
scheme: "bearer",
|
|
1837
|
+
type: "http"
|
|
1838
|
+
}, {
|
|
1839
|
+
in: "cookie",
|
|
1840
|
+
name: "bird_session",
|
|
1841
|
+
type: "apiKey"
|
|
1842
|
+
}],
|
|
1843
|
+
url: "/v1/verify/verifications/check",
|
|
1844
|
+
...options,
|
|
1845
|
+
headers: {
|
|
1846
|
+
"Content-Type": "application/json",
|
|
1847
|
+
...options.headers
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
/**
|
|
1851
|
+
* List WhatsApp messages
|
|
1852
|
+
*
|
|
1853
|
+
* Returns a paginated list of WhatsApp messages in the workspace, newest first.
|
|
1854
|
+
*/
|
|
1855
|
+
const listWhatsAppMessages = (options) => (options?.client ?? client).get({
|
|
1856
|
+
security: [{
|
|
1857
|
+
scheme: "bearer",
|
|
1858
|
+
type: "http"
|
|
1859
|
+
}, {
|
|
1860
|
+
in: "cookie",
|
|
1861
|
+
name: "bird_session",
|
|
1862
|
+
type: "apiKey"
|
|
1863
|
+
}],
|
|
1864
|
+
url: "/v1/whatsapp/messages",
|
|
1865
|
+
...options
|
|
1866
|
+
});
|
|
1867
|
+
/**
|
|
1868
|
+
* Send a message
|
|
1869
|
+
*
|
|
1870
|
+
* Sends a template message. Bird selects the sender number from the template's category.
|
|
1871
|
+
*/
|
|
1872
|
+
const sendWhatsAppMessage = (options) => (options.client ?? client).post({
|
|
1873
|
+
security: [{
|
|
1874
|
+
scheme: "bearer",
|
|
1875
|
+
type: "http"
|
|
1876
|
+
}, {
|
|
1877
|
+
in: "cookie",
|
|
1878
|
+
name: "bird_session",
|
|
1879
|
+
type: "apiKey"
|
|
1880
|
+
}],
|
|
1881
|
+
url: "/v1/whatsapp/messages",
|
|
1882
|
+
...options,
|
|
1883
|
+
headers: {
|
|
1884
|
+
"Content-Type": "application/json",
|
|
1885
|
+
...options.headers
|
|
1886
|
+
}
|
|
1887
|
+
});
|
|
1888
|
+
/**
|
|
1889
|
+
* Get a WhatsApp message
|
|
1890
|
+
*
|
|
1891
|
+
* Returns a single WhatsApp message with its current delivery status and failure detail if applicable.
|
|
1892
|
+
*/
|
|
1893
|
+
const getWhatsAppMessage = (options) => (options.client ?? client).get({
|
|
1894
|
+
security: [{
|
|
1895
|
+
scheme: "bearer",
|
|
1896
|
+
type: "http"
|
|
1897
|
+
}, {
|
|
1898
|
+
in: "cookie",
|
|
1899
|
+
name: "bird_session",
|
|
1900
|
+
type: "apiKey"
|
|
1901
|
+
}],
|
|
1902
|
+
url: "/v1/whatsapp/messages/{message_id}",
|
|
1903
|
+
...options
|
|
1904
|
+
});
|
|
1905
|
+
/**
|
|
1906
|
+
* List events for a WhatsApp message
|
|
1907
|
+
*
|
|
1908
|
+
* Returns the lifecycle event timeline for a WhatsApp message, in chronological order.
|
|
1909
|
+
*/
|
|
1910
|
+
const listWhatsAppMessageEvents = (options) => (options.client ?? client).get({
|
|
1911
|
+
security: [{
|
|
1912
|
+
scheme: "bearer",
|
|
1913
|
+
type: "http"
|
|
1914
|
+
}, {
|
|
1915
|
+
in: "cookie",
|
|
1916
|
+
name: "bird_session",
|
|
1917
|
+
type: "apiKey"
|
|
1918
|
+
}],
|
|
1919
|
+
url: "/v1/whatsapp/messages/{message_id}/events",
|
|
1920
|
+
...options
|
|
1921
|
+
});
|
|
1922
|
+
/**
|
|
1923
|
+
* List available message templates
|
|
1924
|
+
*
|
|
1925
|
+
* Returns the message templates available to this workspace.
|
|
1926
|
+
*/
|
|
1927
|
+
const listWhatsAppTemplates = (options) => (options?.client ?? client).get({
|
|
1928
|
+
security: [{
|
|
1929
|
+
scheme: "bearer",
|
|
1930
|
+
type: "http"
|
|
1931
|
+
}, {
|
|
1932
|
+
in: "cookie",
|
|
1933
|
+
name: "bird_session",
|
|
1934
|
+
type: "apiKey"
|
|
1935
|
+
}],
|
|
1936
|
+
url: "/v1/whatsapp/templates",
|
|
1937
|
+
...options
|
|
1938
|
+
});
|
|
1806
1939
|
//#endregion
|
|
1807
1940
|
//#region src/resources/base.ts
|
|
1808
1941
|
var Resource = class {
|
|
@@ -2499,6 +2632,163 @@ var SmsTemplatesResource = class extends Resource {
|
|
|
2499
2632
|
}
|
|
2500
2633
|
};
|
|
2501
2634
|
//#endregion
|
|
2635
|
+
//#region src/resources/whatsapp.ts
|
|
2636
|
+
var WhatsappResource = class extends Resource {
|
|
2637
|
+
/**
|
|
2638
|
+
* Send a template message. Bird selects the sender number from the
|
|
2639
|
+
* template's category, so there is no sender field on the request. The
|
|
2640
|
+
* result is `accepted`, not yet delivered — read it back with `get` to
|
|
2641
|
+
* confirm.
|
|
2642
|
+
*
|
|
2643
|
+
* @example
|
|
2644
|
+
* const msg = await bird.whatsapp.send({
|
|
2645
|
+
* to: "+15551234567",
|
|
2646
|
+
* template: {
|
|
2647
|
+
* name: "bird_otp",
|
|
2648
|
+
* components: [
|
|
2649
|
+
* { type: "body", parameters: [{ type: "text", text: "123456" }] },
|
|
2650
|
+
* ],
|
|
2651
|
+
* },
|
|
2652
|
+
* });
|
|
2653
|
+
* console.log(msg.id, msg.status);
|
|
2654
|
+
*/
|
|
2655
|
+
send(params, options) {
|
|
2656
|
+
return this.call("POST", options, ({ signal, headers }) => sendWhatsAppMessage({
|
|
2657
|
+
client: this.client,
|
|
2658
|
+
body: params,
|
|
2659
|
+
headers,
|
|
2660
|
+
signal
|
|
2661
|
+
}));
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Fetch a single WhatsApp message: its current delivery status and failure
|
|
2665
|
+
* detail if it failed.
|
|
2666
|
+
*
|
|
2667
|
+
* @example
|
|
2668
|
+
* const msg = await bird.whatsapp.get("wa_abc123");
|
|
2669
|
+
* msg.status; // "accepted" | "delivered" | …
|
|
2670
|
+
*/
|
|
2671
|
+
get(messageId, options) {
|
|
2672
|
+
return this.call("GET", options, ({ signal, headers }) => getWhatsAppMessage({
|
|
2673
|
+
client: this.client,
|
|
2674
|
+
path: { message_id: messageId },
|
|
2675
|
+
headers,
|
|
2676
|
+
signal
|
|
2677
|
+
}));
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* List WhatsApp messages, newest first. `await` resolves the first page;
|
|
2681
|
+
* `for await` walks every message across all pages. Filter by status,
|
|
2682
|
+
* recipient phone number, or business-scoped user ID.
|
|
2683
|
+
*
|
|
2684
|
+
* @example
|
|
2685
|
+
* for await (const msg of bird.whatsapp.list({ status: ["delivered"] })) {
|
|
2686
|
+
* console.log(msg.id, msg.status);
|
|
2687
|
+
* }
|
|
2688
|
+
*/
|
|
2689
|
+
list(query, options) {
|
|
2690
|
+
return this.paginated("GET", options, ({ signal, headers }, cursor) => listWhatsAppMessages({
|
|
2691
|
+
client: this.client,
|
|
2692
|
+
query: {
|
|
2693
|
+
...query,
|
|
2694
|
+
starting_after: cursor ?? query?.starting_after
|
|
2695
|
+
},
|
|
2696
|
+
headers,
|
|
2697
|
+
signal
|
|
2698
|
+
}));
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* List a WhatsApp message's lifecycle event timeline, in chronological
|
|
2702
|
+
* order. The timeline is bounded and returned in full — this list is not
|
|
2703
|
+
* paginated.
|
|
2704
|
+
*
|
|
2705
|
+
* @example
|
|
2706
|
+
* const { data } = await bird.whatsapp.listEvents("wa_abc123");
|
|
2707
|
+
* for (const event of data) console.log(event.type, event.occurred_at);
|
|
2708
|
+
*/
|
|
2709
|
+
listEvents(messageId, query, options) {
|
|
2710
|
+
return this.call("GET", options, ({ signal, headers }) => listWhatsAppMessageEvents({
|
|
2711
|
+
client: this.client,
|
|
2712
|
+
path: { message_id: messageId },
|
|
2713
|
+
query,
|
|
2714
|
+
headers,
|
|
2715
|
+
signal
|
|
2716
|
+
}));
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
//#endregion
|
|
2720
|
+
//#region src/resources/whatsappTemplates.ts
|
|
2721
|
+
var WhatsappTemplatesResource = class extends Resource {
|
|
2722
|
+
/**
|
|
2723
|
+
* List the WhatsApp message templates available to the workspace — Meta's
|
|
2724
|
+
* approved templates for this business account. The catalogue is small and
|
|
2725
|
+
* returned in full (`.data`); this list is not paginated.
|
|
2726
|
+
*
|
|
2727
|
+
* @example
|
|
2728
|
+
* const { data } = await bird.whatsappTemplates.list();
|
|
2729
|
+
* for (const tpl of data) console.log(tpl.name, tpl.status);
|
|
2730
|
+
*/
|
|
2731
|
+
list(options) {
|
|
2732
|
+
return this.call("GET", options, ({ signal, headers }) => listWhatsAppTemplates({
|
|
2733
|
+
client: this.client,
|
|
2734
|
+
headers,
|
|
2735
|
+
signal
|
|
2736
|
+
}));
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2739
|
+
//#endregion
|
|
2740
|
+
//#region src/resources/verify.ts
|
|
2741
|
+
var VerificationsResource = class extends Resource {
|
|
2742
|
+
/**
|
|
2743
|
+
* Start a verification and send a one-time passcode to the recipient in `to`
|
|
2744
|
+
* (a `phone_number` over SMS, an `email_address` over email, or both). Calling
|
|
2745
|
+
* again for the same recipient re-sends the code after the cooldown rather than
|
|
2746
|
+
* starting a second verification. The passcode is never returned — submit the
|
|
2747
|
+
* recipient's entry with `check`.
|
|
2748
|
+
*
|
|
2749
|
+
* @example Start over SMS
|
|
2750
|
+
* const verification = await bird.verify.verifications.create({
|
|
2751
|
+
* to: { phone_number: "+15551234567" },
|
|
2752
|
+
* });
|
|
2753
|
+
* console.log(verification.id, verification.status);
|
|
2754
|
+
*/
|
|
2755
|
+
create(params, options) {
|
|
2756
|
+
return this.call("POST", options, ({ signal, headers }) => createVerification({
|
|
2757
|
+
client: this.client,
|
|
2758
|
+
body: params,
|
|
2759
|
+
headers,
|
|
2760
|
+
signal
|
|
2761
|
+
}));
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Check a passcode the recipient submitted. Identify the verification by the same
|
|
2765
|
+
* `to` recipient used to start it — no id needed. A wrong, expired, or already-used
|
|
2766
|
+
* code resolves with `success: false` and a `reason`, not an error.
|
|
2767
|
+
*
|
|
2768
|
+
* @example
|
|
2769
|
+
* const result = await bird.verify.verifications.check({
|
|
2770
|
+
* to: { phone_number: "+15551234567" },
|
|
2771
|
+
* code: "123456",
|
|
2772
|
+
* });
|
|
2773
|
+
* console.log(result.success);
|
|
2774
|
+
*/
|
|
2775
|
+
check(params, options) {
|
|
2776
|
+
return this.call("POST", options, ({ signal, headers }) => createVerificationCheck({
|
|
2777
|
+
client: this.client,
|
|
2778
|
+
body: params,
|
|
2779
|
+
headers,
|
|
2780
|
+
signal
|
|
2781
|
+
}));
|
|
2782
|
+
}
|
|
2783
|
+
};
|
|
2784
|
+
/** The Verify product namespace — holds the `verifications` collection. */
|
|
2785
|
+
var VerifyResource = class {
|
|
2786
|
+
verifications;
|
|
2787
|
+
constructor(...args) {
|
|
2788
|
+
this.verifications = new VerificationsResource(...args);
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
//#endregion
|
|
2502
2792
|
//#region src/resources/webhooks.ts
|
|
2503
2793
|
var WebhooksResource = class {
|
|
2504
2794
|
#secret;
|
|
@@ -2619,6 +2909,12 @@ var BirdClient = class {
|
|
|
2619
2909
|
sms;
|
|
2620
2910
|
/** SMS templates — `bird.smsTemplates.list(...)`, `.get(...)`. */
|
|
2621
2911
|
smsTemplates;
|
|
2912
|
+
/** The WhatsApp channel — `bird.whatsapp.send(...)`, `.get(...)`, `.list(...)`, `.listEvents(...)`. */
|
|
2913
|
+
whatsapp;
|
|
2914
|
+
/** WhatsApp templates — `bird.whatsappTemplates.list(...)`. */
|
|
2915
|
+
whatsappTemplates;
|
|
2916
|
+
/** The Verify product — `bird.verify.verifications.create(...)`, `.check(...)`. */
|
|
2917
|
+
verify;
|
|
2622
2918
|
/** Contacts — `bird.contacts.create(...)`, `.list(...)`, `.get(...)`, `.batch(...)`, … */
|
|
2623
2919
|
contacts;
|
|
2624
2920
|
/** Audiences — `bird.audiences.create(...)`, `.list(...)`, `.addContacts(...)`, … */
|
|
@@ -2634,9 +2930,9 @@ var BirdClient = class {
|
|
|
2634
2930
|
this.#headers = {
|
|
2635
2931
|
...opts.defaultHeaders,
|
|
2636
2932
|
Authorization: `Bearer ${opts.apiKey}`,
|
|
2637
|
-
"User-Agent": `bird-sdk-js/0.
|
|
2933
|
+
"User-Agent": `bird-sdk-js/0.7.0`,
|
|
2638
2934
|
"Bird-Surface": "sdk-js",
|
|
2639
|
-
"Bird-Version": "0.
|
|
2935
|
+
"Bird-Version": "0.7.0"
|
|
2640
2936
|
};
|
|
2641
2937
|
const caller = detectCaller();
|
|
2642
2938
|
if (caller) this.#headers["Bird-Caller"] = caller;
|
|
@@ -2652,6 +2948,9 @@ var BirdClient = class {
|
|
|
2652
2948
|
this.email = new EmailResource(this.core, this.#client, opts.email);
|
|
2653
2949
|
this.sms = new SmsResource(this.core, this.#client);
|
|
2654
2950
|
this.smsTemplates = new SmsTemplatesResource(this.core, this.#client);
|
|
2951
|
+
this.whatsapp = new WhatsappResource(this.core, this.#client);
|
|
2952
|
+
this.whatsappTemplates = new WhatsappTemplatesResource(this.core, this.#client);
|
|
2953
|
+
this.verify = new VerifyResource(this.core, this.#client);
|
|
2655
2954
|
this.contacts = new ContactsResource(this.core, this.#client);
|
|
2656
2955
|
this.audiences = new AudiencesResource(this.core, this.#client);
|
|
2657
2956
|
this.contactProperties = new ContactPropertiesResource(this.core, this.#client);
|
|
@@ -2728,8 +3027,6 @@ const WebhookEventType = {
|
|
|
2728
3027
|
EmailMailboxMessageDelivered: "email_mailbox.message_delivered",
|
|
2729
3028
|
EmailMailboxMessageFailed: "email_mailbox.message_failed",
|
|
2730
3029
|
EmailMailboxMessageReceived: "email_mailbox.message_received",
|
|
2731
|
-
EmailMailboxMessageReceivedBlocked: "email_mailbox.message_received_blocked",
|
|
2732
|
-
EmailMailboxMessageReceivedUnauthenticated: "email_mailbox.message_received_unauthenticated",
|
|
2733
3030
|
EmailMailboxMessageSent: "email_mailbox.message_sent",
|
|
2734
3031
|
EmailMailboxSuspended: "email_mailbox.suspended",
|
|
2735
3032
|
EmailMailboxThreadCreated: "email_mailbox.thread_created",
|