Twilio SMS
Send SMS through the Twilio Messages API with createSmsSender.
Use Twilio when your SMS traffic should go through the Programmable Messaging Messages API.
Wire TwilioSmsTransport into createSmsSender — Verify, Voice, and other Twilio products stay off this transport.
The one rule
Provide From or messagingServiceSid (or both), keep E.164 + prefixes, and send only
through createSmsSender.
Quick start
Configure
import { createSmsSender } from "sently/sms";
import { TwilioSmsTransport } from "sently/transports/twilio-sms";
const sms = createSmsSender({
transport: new TwilioSmsTransport({
accountSid: process.env.TWILIO_ACCOUNT_SID!,
apiKey: process.env.TWILIO_API_KEY!,
authToken: process.env.TWILIO_API_KEY_SECRET!,
from: "+15557654321",
}),
});Production auth: API Key SID as Basic username and API Key Secret as password, with Account SID still in the URL path.
For local testing you may omit apiKey and use Account SID + Auth Token.
Send
const result = await sms.send({
to: "+15551234567",
body: "Your code is 123456",
});See the result
console.log(result.messageId); // SM…
console.log(result.status); // e.g. queuedConfiguration
| Option | Type | Default | Meaning |
|---|---|---|---|
accountSid | string | required | Account SID in the Messages URL path. |
authToken | string | required | Auth Token, or API Key Secret when apiKey is set. |
apiKey | string | — | API Key SID used as Basic-auth username (recommended in production). |
from | string | — | Default From number / sender id. |
messagingServiceSid | string | — | Messaging Service SID (MG…) as sender alternative. |
statusCallback | string | — | Delivery status callback URL. |
Either from / options.from or messagingServiceSid is required for each send.
Messaging Service
When messagingServiceSid is set and From is omitted, Twilio picks a sender from the service pool.
You may set both to pin a specific From inside that pool.
const sms = createSmsSender({
transport: new TwilioSmsTransport({
accountSid: process.env.TWILIO_ACCOUNT_SID!,
authToken: process.env.TWILIO_AUTH_TOKEN!,
messagingServiceSid: "MG…",
}),
});Verify and errors
verify() fetches GET /2010-04-01/Accounts/{AccountSid}.json with the same Basic credentials.
Failed Messages responses throw TwilioSmsError with Twilio’s message / code payload when present.
Troubleshooting
Set from on the transport or per send, or configure messagingServiceSid.
Twilio expects E.164 with a leading +. Do not strip + the way some regional SMS APIs require.
Learn more
- SMS channel —
createSmsSenderand hooks - Transports — other SMS providers