AI disclosure: this article was written with the help of AI and checked by a human before publishing.
Sending SMS gets all the attention. Receiving it is where apps get into trouble. The moment you send marketing or notification texts, people reply, and some of those replies are legal instructions: STOP means stop. Here is how I build the inbound side so it is correct from day one.
How an inbound message reaches you
When someone texts your number, the carrier hands the message to your provider, and your provider makes an HTTP POST to a webhook URL you set on the number. The body usually carries the sender in E.164, your number, the text, a message ID and a timestamp.
Three things follow from that:
- Your endpoint must be public, fast and always up. If it is down, the provider retries, and you may get the same message twice.
- Anyone can POST to a public URL, so verify the request signature before you trust it.
- The message ID is your de-duplication key.
The keywords you must handle
Rules differ by country, but these words are treated as opt-out or help requests almost everywhere I have shipped:
- Opt out: STOP, STOPALL, UNSUBSCRIBE, CANCEL, END, QUIT
- Opt back in: START, UNSTOP, YES
- Help: HELP, INFO
Match on the whole message after trimming and upper-casing. "Stop " with a trailing space is still STOP. "Please stop texting me" should also be treated as an opt-out by a sensible app, even if no rule forces you to.
A handler that gets it right
const OPT_OUT = new Set(['STOP', 'STOPALL', 'UNSUBSCRIBE', 'CANCEL', 'END', 'QUIT']); const OPT_IN = new Set(['START', 'UNSTOP', 'YES']); app.post('/sms/inbound', verifySignature, async (req, res) => { const { message_id, from, to, text } = req.body; if (await seen(message_id)) return res.sendStatus(200); // retry, already handled await remember(message_id); const word = String(text || '').trim().toUpperCase(); if (OPT_OUT.has(word) || /\bstop\b/i.test(text)) await optOut(from, to); else if (OPT_IN.has(word)) await optIn(from, to); else if (word === 'HELP' || word === 'INFO') await queueHelpReply(from, to); else await queueForHuman(from, to, text); res.sendStatus(200); // answer fast, do the slow work from a queue }); Rules that keep you out of trouble
- Check the opt-out list on every send, inside the send function itself, not in the campaign tool. A list that is only checked in one place will be bypassed by the next feature someone builds.
- Scope opt-outs to the sender number or brand, and store when and how the person opted out. You will be asked.
- Send one confirmation after STOP and then nothing else. Do not send "Are you sure?".
- Keep the HELP reply short: who you are, what the messages are and how to stop them.
- Never treat a send response as consent. Consent comes from your own records.
Try it yourself
To try the webhook side, sign up and run the webhooks example. It receives signed webhooks and verifies their signatures, the same pattern as the handler above.
The code is open on GitHub:
- Runnable examples in eight languages, including a signed webhook receiver
- Node.js and TypeScript library and Python library
- OpenAPI specification for the webhook payloads
- MCP server: connect any MCP client to
https://packetexchange.io/mcp/httpand an agent can send an SMS or run a verification. Read the MCP overview
How do you handle replies that are not keywords, such as "who is this?"
