Schedule icon
Request icon
Return icon
Switch icon
Log icon
SlackIncomingWebhook icon

Twilio SMS Delivery Sentinel

Read recent Twilio outbound messages every hour, change nothing, and alert Slack when SMS failures cross your limits, with the top error code.

Categories
Business

One-time passwords, delivery updates and appointment reminders go out as SMS, and when a carrier starts filtering a sender, a sender registration lapses, or a number runs out of balance, messages quietly come back failed or undelivered. Users simply cannot log in, and the team hears about it from support tickets. Twilio records every outcome and an error code, but nobody watches the rate. This blueprint turns a scheduled, read-only call to the Twilio Messages API into an SMS delivery gate: io.kestra.plugin.core.http.Request reads recent outbound messages, one jq query computes the failure rate and the most common error code, and the result routes to a quiet log or a Slack alert.

How it works

  1. list_messages (io.kestra.plugin.core.http.Request) calls GET /2010-04-01/Accounts/{AccountSid}/Messages.json with PageSize=1000 and a DateSent>= filter for the lookback window, using HTTP basic auth with the Account SID and Auth Token. It is a read: nothing is sent, redacted or deleted. Retries cover short network blips, and allowFailed plus allowFailure keep an API error from aborting the flow so it can be reported instead.
  2. summarize_delivery (io.kestra.plugin.core.debug.Return) first guards for a missing or non-200 response (UNREACHABLE). Otherwise one jq query keeps outbound messages (direction starting with outbound) whose status is final (delivered, sent, undelivered, failed), ignores ones still queued or sending, computes the share that failed or came back undelivered, and finds the most common error_code. Fewer than min_messages finished messages is LOW_VOLUME; at or above critical_failure_rate is CRITICAL; at or above warning_failure_rate is WARNING; otherwise HEALTHY.
  3. route_by_delivery (io.kestra.plugin.core.flow.Switch) branches on that classification: HEALTHY and LOW_VOLUME log quietly, WARNING posts a Slack note, CRITICAL and UNREACHABLE page Slack. A defaults fallback logs anything unexpected.
  4. log_audit_result (io.kestra.plugin.core.log.Log) writes one audit line per run with the HTTP status and the full summary.
  5. The flow-level errors block pages Slack if the flow itself fails, and the hourly_check trigger runs at 35 minutes past every hour, shipped disabled: true.

What you get

  • An hourly, read-only SMS delivery check with no custom scripting and no extra plugin to install.
  • A status output (HEALTHY / WARNING / CRITICAL / LOW_VOLUME / UNREACHABLE) other flows can gate on, for example to switch OTPs to WhatsApp or email while SMS is failing.
  • Slack messages with the failure rate and the most common Twilio error code, which points straight at the cause (for example carrier filtering or an unregistered sender).
  • An audit line on every run, separate from Slack.

Who it's for

  • Apps that send OTPs, order updates or reminders by SMS through Twilio, including Indian businesses that must keep DLT sender registration in order.
  • Support and engineering teams who want to hear about an SMS problem before users report "I didn't get the code".
  • Teams that already run their alerting in Kestra.

Why orchestrate this with Kestra

Twilio's console shows message logs and its status callbacks report one message at a time. Kestra turns a plain, read-only API call into a scheduled, typed classification with retries, a failure path and an execution history, and the status output lets your messaging flows fall back to another channel automatically.

Prerequisites

  • A Twilio account sending SMS (a trial account works for testing) and its Account SID and Auth Token from the Console.
  • A Slack incoming webhook for the WARNING, CRITICAL, UNREACHABLE and flow-failure alerts.

Secrets

  • TWILIO_ACCOUNT_SID: the Account SID (starts with AC).
  • TWILIO_AUTH_TOKEN: the matching Auth Token (or an API key secret, if you use an API key SID as the username instead).
  • SLACK_WEBHOOK: Slack incoming webhook used for every alert branch and the flow-failure alert.

In Kestra OSS, secrets are supplied as environment variables prefixed SECRET_ and base64-encoded, for example SECRET_TWILIO_ACCOUNT_SID=$(echo -n 'ACxxxxxxxx' | base64), and read back with {{ secret('TWILIO_ACCOUNT_SID') }}. Use the Enterprise secrets backend for encryption at rest and access control.

Quick start

  1. In a Twilio trial account, verify your own phone number and send yourself a few test SMS, plus one to an invalid number to produce a failure.
  2. Add TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN and SLACK_WEBHOOK as secrets.
  3. Run the flow manually with a low min_messages and compare the counts and error code in the logs with the Messaging logs in the Console.
  4. Enable hourly_check.

How to extend

  • Follow next_page_uri when you send more than 1,000 messages in the window.
  • Filter by From to watch one sender (for example the OTP short code) with its own limits.
  • Look up the top error code in Twilio's error dictionary and include the meaning in the Slack text.
  • Store the last status in a KV store and alert only when it changes.

Inputs

  • lookback_days: type INT, default 1.
  • warning_failure_rate: type FLOAT, default 5.0 (percent).
  • critical_failure_rate: type FLOAT, default 15.0 (percent).
  • min_messages: type INT, default 50.

Outputs

  • status: one of HEALTHY, WARNING, CRITICAL, LOW_VOLUME, UNREACHABLE.
  • Example path: {{ fromJson(outputs.summarize_delivery.value).top_error }} for the most common error code.

Links

Pitfalls

  • Only the first page (up to 1,000 messages) is read; high-volume senders need paging with next_page_uri or a shorter window.
  • The date filter works on whole days (UTC), so lookback_days: 1 covers yesterday and today so far.
  • sent means the carrier accepted the message but no delivery receipt came back; it is counted as finished but not as a failure, because many routes never return receipts.
  • This flow only reads; it never sends, redacts or deletes a message.
See How

New to Kestra?

Use blueprints to kickstart your first workflows.