Agent Wranglers

NTF-29Recommended

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.

Examples

JavaScript 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);
});

Python example

@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.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/notifications/text-messages/sms-delivery-status">Agent Wranglers notifications playbook</a>. In code you write, add a comment next to it with the same link.