send-notification.ts
202 · 0.4s
import { BirdClient } from "@messagebird/sdk";
const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });
const { data, error } = await bird.sms.send({
from: "Bird",
to: "+15005550006",
text: "Your order #4821 has shipped. Track it: bird.ly/t/4821x",
category: "transactional",
}).safe();
if (error) throw error;
console.log(data.id);
// → "sms_4kT01Lq2m..."
Hi Ada, reminder of your appointment tomorrow at 14:30 with Dr. Kowalski.
Your order #4821 has shipped. Track it: bird.ly/t/4821x
Your subscription renews on 3 Sep for €12/mo. Manage it here: bird.ly/account
四种发送者类型,一套 API。
号码是 Bird SMS API 的基础。用你已经在使用的同一客户端搜索可用性、购买号码,并将入站路由到一个 webhook。你选择哪种类型取决于用量、地域,以及你能承担多少注册工作。
我应该使用哪种发送者?
吞吐量、覆盖范围和注册工作量因发送者类型而异。大多数美国应用流量从 10DLC 长码起步;大批量一对多项目会转向短码。
| 发送者类型 | 最适合 | 注册 |
|---|---|---|
| 长码(10DLC) | 中等用量下的双向对话、OTP、提醒 | A2P 10DLC 品牌 + 活动 |
| 短码 | 大批量一对多营销和提醒 | 运营商审核,前置周期以周计 |
| 免费电话号码 | 无需 10DLC 的美国/加拿大流量,吞吐量高于长码 | 免费电话号码验证 |
| 字母数字发送者 ID | 在国家/地区允许的地方进行单向品牌提醒 | 许多国家/地区需要预注册 |
选择一种号码类型
深入了解每种发送方类型:覆盖范围、吞吐量及注册要求。
几次调用即可搜索、购买并路由。
按国家/地区和功能查找号码,购买后将其入站流量指向 Webhook——全部通过您发送消息所用的同一 SDK 完成。号码在所需注册审批通过后即刻生效。
provision.ts
201 · purchased
const { data: available } = await bird.numbers.search({
country: "US",
type: "long-code",
capabilities: ["sms"],
}).safe();
const { data: number } = await bird.numbers.buy({
number: available[0].number,
webhook: "https://example.com/webhooks/bird",
}).safe();
console.log(number.id); // → "num_8KQ2..."