@messagebird/sdk 0.23.0 → 0.24.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.mjs CHANGED
@@ -1950,6 +1950,8 @@ const unassignAudienceContact = (options) => (options.client ?? client).delete({
1950
1950
  *
1951
1951
  * Returns the workspace's SMS messages as a cursor-paginated list, newest first. Filter by direction, status, category, recipient, sender, failure reason, tag, or creation time; pass the response's `next_cursor` back as `starting_after` to fetch the next page. To follow a single message's delivery, use [Get an SMS message](/docs/api/reference/get-sms-message) instead.
1952
1952
  *
1953
+ * Messages are retained for **30 days**. A `created_after` earlier than that is accepted and raised to the retention bound rather than rejected, so a wider window returns what is still retained instead of failing. There is no way to read messages older than the window.
1954
+ *
1953
1955
  */
1954
1956
  const listSmsMessages = (options) => (options?.client ?? client).get({
1955
1957
  security: [{
@@ -2088,7 +2090,7 @@ const getSmsTemplate = (options) => (options.client ?? client).get({
2088
2090
  /**
2089
2091
  * Create a verification
2090
2092
  *
2091
- * Creates a verification for a recipient and sends them a one-time passcode. Provide the recipient in `to`: an email address (verified over email), a phone number (verified over SMS), or both. With both, the passcode is sent over one channel at a time and delivery falls over to the other channel if the first fails; it is never sent to both at once.
2093
+ * Creates a verification for a recipient and sends them a one-time passcode. Provide the recipient in `to`: an email address (verified over email), a phone number (verified over the phone channels enabled for its destination country), or both. The passcode is sent over one channel at a time and delivery falls over to the next channel in the plan if one fails; it is never sent over two channels at once.
2092
2094
  *
2093
2095
  * Calling this again for the same recipient resumes the verification in progress rather than starting a second one: within the resend cooldown the request returns the current state without sending, and after it a fresh passcode is sent. Use the same call to send and to resend.
2094
2096
  *
@@ -2138,10 +2140,38 @@ const createVerificationCheck = (options) => (options.client ?? client).post({
2138
2140
  }
2139
2141
  });
2140
2142
  /**
2143
+ * Advance a verification to its next channel
2144
+ *
2145
+ * Advances an in-progress verification to the next channel in its plan and sends a fresh passcode there, for a recipient who reports not receiving the code. Identify the verification by the same `to` used to create it; you do not need to store a verification ID.
2146
+ *
2147
+ * The send bypasses the resend cooldown (a deliberate channel switch is a different act from a same-channel resend), and every passcode already sent stays valid, so a code that arrives late can still be checked. The response is the verification with `last_channel` set to the channel the new passcode went to. Concurrent requests for the same recipient are safe: each advances the plan at most one step. When two race, the request that completes the newer send is the authoritative one; the other returns the verification's committed state, whose `last_channel` still names the most recent send that completed. A later read of the verification always reflects the settled outcome.
2148
+ *
2149
+ * An error status is returned when the verification cannot be advanced: `404` when no verification is in progress for the recipient, `422` with `NoNextChannel` when the plan has no further channel (fall back to a plain resend), `422` with `NoAvailableChannel` when every remaining channel failed to send, and `429` when sends for the account are requested too quickly.
2150
+ *
2151
+ */
2152
+ const createVerificationNextChannel = (options) => (options.client ?? client).post({
2153
+ security: [{
2154
+ scheme: "bearer",
2155
+ type: "http"
2156
+ }, {
2157
+ in: "cookie",
2158
+ name: "bird_session",
2159
+ type: "apiKey"
2160
+ }],
2161
+ url: "/v1/verify/verifications/next-channel",
2162
+ ...options,
2163
+ headers: {
2164
+ "Content-Type": "application/json",
2165
+ ...options.headers
2166
+ }
2167
+ });
2168
+ /**
2141
2169
  * List WhatsApp messages
2142
2170
  *
2143
2171
  * Returns the workspace's WhatsApp messages as a cursor-paginated list, newest first. Filter by direction, status, contact phone number, business-scoped user ID, template category, tag, or creation time; pass the response's `next_cursor` back as `starting_after` to fetch the next page. To follow a single message's delivery, use [Get a WhatsApp message](/docs/api/reference/get-whats-app-message) instead.
2144
2172
  *
2173
+ * Messages are retained for **30 days**. A `created_after` earlier than that is accepted and raised to the retention bound rather than rejected, so a wider window returns what is still retained instead of failing. There is no way to read messages older than the window.
2174
+ *
2145
2175
  */
2146
2176
  const listWhatsAppMessages = (options) => (options?.client ?? client).get({
2147
2177
  security: [{
@@ -3154,6 +3184,47 @@ const listMailboxLabels = (options) => (options.client ?? client).get({
3154
3184
  url: "/v1/email/mailboxes/{mailbox_id}/labels",
3155
3185
  ...options
3156
3186
  });
3187
+ /**
3188
+ * List calls
3189
+ *
3190
+ * Returns a paginated list of the workspace's calls, ordered by start time descending.
3191
+ *
3192
+ * The `status` filter selects which side of the call lifecycle you get. Omit it, or pass only final statuses, and you get completed calls. Pass only the in-flight statuses (`ringing`, `in_progress`) and you get the calls happening right now. A call in flight carries no economics yet: `duration_ms`, `billable_ms`, `ended_at`, and `cost` are null until it ends, and the completed record then appears under the same `id`.
3193
+ *
3194
+ * In-flight and completed calls are paged separately, so a request that mixes in-flight and final statuses returns a 422 `validation_error`.
3195
+ *
3196
+ */
3197
+ const listVoiceCalls = (options) => (options?.client ?? client).get({
3198
+ querySerializer: { parameters: { status: { array: { explode: false } } } },
3199
+ security: [{
3200
+ scheme: "bearer",
3201
+ type: "http"
3202
+ }, {
3203
+ in: "cookie",
3204
+ name: "bird_session",
3205
+ type: "apiKey"
3206
+ }],
3207
+ url: "/v1/voice/calls",
3208
+ ...options
3209
+ });
3210
+ /**
3211
+ * Get a call
3212
+ *
3213
+ * Returns a single call at any point in its lifecycle. A call that is still ringing or connected answers with its in-flight `status` and no economics: `duration_ms`, `billable_ms`, `ended_at`, and `cost` fill in once it ends, at this same URL. Returns a 404 `not_found_error` if the call does not exist in the workspace.
3214
+ *
3215
+ */
3216
+ const getVoiceCall = (options) => (options.client ?? client).get({
3217
+ security: [{
3218
+ scheme: "bearer",
3219
+ type: "http"
3220
+ }, {
3221
+ in: "cookie",
3222
+ name: "bird_session",
3223
+ type: "apiKey"
3224
+ }],
3225
+ url: "/v1/voice/calls/{call_id}",
3226
+ ...options
3227
+ });
3157
3228
  //#endregion
3158
3229
  //#region src/resources/base.ts
3159
3230
  var Resource = class {
@@ -4767,10 +4838,49 @@ var WhatsappResource = class extends WhatsappResourceBase {
4767
4838
  }
4768
4839
  };
4769
4840
  //#endregion
4841
+ //#region src/resources/voice.gen.ts
4842
+ var VoiceResource = class extends Resource {
4843
+ /**
4844
+ * List the workspace's calls, newest first. Filter to `ringing`/`in_progress` for the calls in progress right now, or to final statuses for completed records. The two cannot be combined in one request. Use `from`/`to` for one known party number in international form, and `number` to search either side by fragment. These are per-call records: for rates and totals over a period use voice_stats_summary rather than summing them here, and voice_get to follow one call to settlement.
4845
+ *
4846
+ * @example Iterate the calls happening right now
4847
+ * for await (const call of bird.voice.list({ status: ["ringing", "in_progress"] })) {
4848
+ * console.log(call.id, call.status);
4849
+ * }
4850
+ */
4851
+ list(query, options) {
4852
+ return this.paginated("GET", options, ({ signal, headers }, cursor) => listVoiceCalls({
4853
+ client: this.client,
4854
+ query: {
4855
+ ...query,
4856
+ starting_after: cursor ?? query?.starting_after
4857
+ },
4858
+ headers,
4859
+ signal
4860
+ }));
4861
+ }
4862
+ /**
4863
+ * Fetch one call by id, at any point in its lifecycle. A call still ringing or connected carries no economics yet: `duration_ms`, `billable_ms`, `ended_at`, and `cost` are null until it ends, and this same id then answers with the settled record. Poll here to watch one known call; use voice_list to find calls in the first place. When a call was refused, `rejection_reason` names the gate that turned it away.
4864
+ *
4865
+ * @example Read one call back
4866
+ * const call = await bird.voice.get("vcl_01k0p3v9wera3v6q6xw3e9y2mh");
4867
+ * // A call still ringing or connected carries no economics yet.
4868
+ * call.status; // "answered" | "no_answer" | "ringing" | …
4869
+ */
4870
+ get(callId, options) {
4871
+ return this.call("GET", options, ({ signal, headers }) => getVoiceCall({
4872
+ client: this.client,
4873
+ path: { call_id: callId },
4874
+ headers,
4875
+ signal
4876
+ }));
4877
+ }
4878
+ };
4879
+ //#endregion
4770
4880
  //#region src/resources/verifyVerifications.gen.ts
4771
4881
  var VerifyVerificationsResource = class extends Resource {
4772
4882
  /**
4773
- * Start a verification: generate a one-time passcode and send it to the recipient in `to` (a phone number over SMS, an email address over email, or both; with both, it is sent over one channel and fails over to the other, not to both at once). Calling again for the same recipient reuses the in-progress verification and sends a fresh code after the resend cooldown; it does not start a second one, so use this both to send and to resend. The passcode is never returned; submit what the recipient enters with verify_verifications_check. SMS delivery draws on the workspace's SMS balance.
4883
+ * Start a verification: generate a one-time passcode and send it to the recipient in `to` (a phone number over the phone channels enabled for its destination country; an email address over email; or both). It is sent over one channel at a time and fails over to the next in the plan, never over two at once. Calling again for the same recipient reuses the in-progress verification and sends a fresh code after the resend cooldown; it does not start a second one, so use this both to send and to resend. The passcode is never returned; submit what the recipient enters with verify_verifications_check. SMS delivery draws on the workspace's SMS balance.
4774
4884
  *
4775
4885
  * @example Start a verification over SMS
4776
4886
  * const verification = await bird.verify.verifications.create({
@@ -4804,6 +4914,23 @@ var VerifyVerificationsResource = class extends Resource {
4804
4914
  signal
4805
4915
  }));
4806
4916
  }
4917
+ /**
4918
+ * Advance an in-progress verification to the next channel in its plan and send a fresh passcode there: the "I didn't receive my code" action. The verification is identified by the same `to` recipient used to start it, with no verification id needed. The send bypasses the resend cooldown, and earlier passcodes stay valid. Returns the verification with `last_channel` set to the channel the new code went to; when concurrent advances race for the same recipient, the response reflects committed state: `last_channel` names the most recent completed send, and the racing call that completed the newer send is authoritative. A plan with no further channel returns a 422 named NoNextChannel, after which only re-creating the verification will resend.
4919
+ *
4920
+ * @example Send the code again on the next channel
4921
+ * const verification = await bird.verify.verifications.nextChannel({
4922
+ * to: { phone_number: "+15551234567" },
4923
+ * });
4924
+ * console.log(verification.last_channel);
4925
+ */
4926
+ nextChannel(params, options) {
4927
+ return this.call("POST", options, ({ signal, headers }) => createVerificationNextChannel({
4928
+ client: this.client,
4929
+ body: params,
4930
+ headers,
4931
+ signal
4932
+ }));
4933
+ }
4807
4934
  };
4808
4935
  //#endregion
4809
4936
  //#region src/resources/verify.ts
@@ -5088,6 +5215,8 @@ var BirdClient = class {
5088
5215
  smsTemplates;
5089
5216
  /** The WhatsApp channel — `bird.whatsapp.send(...)`, `.get(...)`, `.list(...)`, `.listEvents(...)`. */
5090
5217
  whatsapp;
5218
+ /** The Voice call log — `bird.voice.list(...)`, `.get(...)`. Calls are placed by your own SIP equipment, so this is a read surface. */
5219
+ voice;
5091
5220
  /** The Verify product — `bird.verify.verifications.create(...)`, `.check(...)`. */
5092
5221
  verify;
5093
5222
  /** Contacts — `bird.contacts.create(...)`, `.list(...)`, `.get(...)`, `.batch(...)`, … */
@@ -5109,9 +5238,9 @@ var BirdClient = class {
5109
5238
  this.#headers = {
5110
5239
  ...opts.defaultHeaders,
5111
5240
  Authorization: `Bearer ${opts.apiKey}`,
5112
- "User-Agent": `bird-sdk-js/0.23.0`,
5241
+ "User-Agent": `bird-sdk-js/0.24.0`,
5113
5242
  "Bird-Surface": "sdk-js",
5114
- "Bird-Version": "0.23.0"
5243
+ "Bird-Version": "0.24.0"
5115
5244
  };
5116
5245
  const caller = detectCaller();
5117
5246
  if (caller) this.#headers["Bird-Caller"] = caller;
@@ -5140,6 +5269,7 @@ var BirdClient = class {
5140
5269
  this.sms = new SmsResource(this.core, this.#client);
5141
5270
  this.smsTemplates = new SmsTemplatesResource(this.core, this.#client);
5142
5271
  this.whatsapp = new WhatsappResource(this.core, this.#client);
5272
+ this.voice = new VoiceResource(this.core, this.#client);
5143
5273
  this.verify = new VerifyResource(this.core, this.#client);
5144
5274
  this.contacts = new ContactsResource(this.core, this.#client);
5145
5275
  this.audiences = new AudiencesResource(this.core, this.#client);