Text messages Recommended
Track what happened to each text
Record the provider's delivery status for every text through a signed callback, and stop sending to numbers that keep failing.
How to do it
Pass a status callback address with each send and verify its signature, as in verify webhook signatures. Store the provider's message ID, status, error code and cost against the send. Do not retry a text marked undelivered for an invalid or unreachable number. Suppress a number after 3 such failures in a row. Watch daily cost per country next to the pumping alerts.
Example
app.post('/sms/status', verifyProviderSignature, async (req, res) => {
const { MessageSid, MessageStatus, ErrorCode, To } = req.body;
await db.sends.updateStatus(MessageSid, MessageStatus, ErrorCode);
if (MessageStatus === 'undelivered' && (await db.sends.recentFailures(To)) >= 3) await db.smsSuppressions.add(To);
res.sendStatus(204);
});
@app.post("/sms/status")
def sms_status():
verify_provider_signature(request)
form = request.form
db.sends.update_status(form["MessageSid"], form["MessageStatus"], form.get("ErrorCode"))
if form["MessageStatus"] == "undelivered" and db.sends.recent_failures(form["To"]) >= 3:
db.sms_suppressions.add(form["To"])
return "", 204
How to check
Send to a provider test number that always fails. The send row shows the failure code, and after the third failure the number is suppressed.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers notifications playbook: https://agentwranglers.se/playbook/notifications/text-messages/sms-delivery-status.