SMS delivery looks like a simple POST request until you hit the parts that actually determine whether messages reach users reliably — carrier filtering, opt-out compliance, and delivery status tracking, none of which show up until you're operating at real volume.
Twilio is a cloud communications platform providing APIs for SMS, voice, and other messaging channels. Its SMS API lets you send and receive text messages programmatically, track delivery status via webhooks, and handle two-way conversations — the foundation for OTP verification, notifications, and conversational SMS features.
Why Twilio SMS Matters (and When to Skip It)
Building direct carrier integrations for SMS is impractical for most teams — Twilio abstracts carrier relationships, number provisioning, and delivery infrastructure behind a simple API, handling the genuinely hard parts (carrier filtering, international routing, compliance requirements) that would otherwise require significant telecom expertise.
Skip Twilio if your notification needs are fully served by push notifications or email — SMS carries real per-message cost and stricter compliance requirements (opt-in consent, opt-out handling) than other channels, so it's worth reserving for cases where SMS specifically is the right channel (OTP, time-sensitive alerts).
Getting Started with Twilio SMS
import twilio from "twilio";
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
await client.messages.create({
from: process.env.TWILIO_PHONE_NUMBER,
to: "+15551234567",
body: "Your verification code is 482913",
});
Handling delivery status via webhook:
app.post("/webhooks/twilio/status", (req, res) => {
const { MessageSid, MessageStatus } = req.body;
// MessageStatus: queued, sent, delivered, failed, undelivered
updateMessageStatus(MessageSid, MessageStatus);
res.sendStatus(200);
});
Receiving inbound SMS replies:
app.post("/webhooks/twilio/inbound", (req, res) => {
const { From, Body } = req.body;
handleIncomingMessage(From, Body);
res.type("text/xml").send("<Response></Response>");
});
Core Twilio SMS Concepts Every Developer Should Know
Delivery status is asynchronous and requires a status callback webhook, not returned synchronously from the send call. The initial API response confirms the message was accepted for sending, not that it was delivered — actual delivery confirmation arrives later via webhook.
Opt-out (STOP) handling is a legal requirement, not optional, in most jurisdictions. Twilio handles the basic STOP/START keyword processing automatically for many number types, but your application should still respect and track opt-out status to avoid sending to users who've unsubscribed.
Message segmentation affects cost. SMS messages over 160 characters (or 70 for non-GSM character sets, like many non-Latin scripts) get split into multiple segments, each billed separately — worth being deliberate about message length and character set for cost-sensitive, high-volume sending.
Alphanumeric sender IDs and dedicated numbers behave differently across countries — some countries require pre-registered sender IDs, others block certain traffic types entirely without proper registration (like A2P 10DLC registration in the US). This varies enough by region that it's worth checking Twilio's specific country requirements before launching to a new market.
Common Twilio SMS Mistakes and How to Fix Them
Mistake 1: treating the send API response as delivery confirmation. The message can still fail or be undelivered after the API call succeeds. Fix: consume the status callback webhook and track actual delivery status, especially for anything time-sensitive like OTP codes.
Mistake 2: not handling opt-outs properly, continuing to message users who've replied STOP. This risks compliance violations and carrier filtering of your traffic. Fix: track opt-out status from Twilio's webhook events and check it before every send.
Mistake 3: skipping A2P 10DLC registration for US traffic, causing messages to be filtered or blocked by carriers without clear errors. Fix: register your use case and brand with Twilio's A2P 10DLC process before sending meaningful volume to US numbers.
When Should You Use Twilio Instead of a Simpler SMS Provider?
Use Twilio when you need broad international coverage, two-way messaging, or are already using other Twilio products (Voice, Verify) that integrate well together. Use a narrower, cheaper alternative when your needs are simple, single-country, one-way notifications, where a lighter-weight provider might offer better pricing for that specific use case.
Twilio SMS in Production
Monitor delivery status and failure rates via webhooks, and set up alerting on unexpected spikes in failed deliveries — a sudden failure spike often signals a carrier filtering issue or an opt-out compliance problem worth investigating immediately. Also complete required registrations (A2P 10DLC, or country-specific sender ID requirements) well before you need to send at volume, since approval processes can take time.
Before sending SMS to real users, confirm opt-out handling and delivery status tracking are both wired up — those are the two things that turn into compliance or reliability problems if skipped.