Skip to main content

Twilio SMS Destination

Send SMS messages via the Twilio REST API — one message per source row, with Jinja2-templated recipient number and body.

YAML Example​

destination:
type: twilio
account_sid_env: TWILIO_ACCOUNT_SID
auth_token_env: TWILIO_AUTH_TOKEN
from_number: "+15551234567"
to_template: "{{ row.phone }}"
message_template: "Hi {{ row.name }}, your order {{ row.order_id }} has shipped."

Configuration​

FieldTypeDefaultDescription
type"twilio"—Required
account_sidstring | nullnullAccount SID (direct value)
account_sid_envstring | nullnullEnv var holding the Account SID
auth_tokenstring | nullnullAuth token (direct value)
auth_token_envstring | nullnullEnv var holding the auth token
from_numberstring—Twilio sending number in E.164 format (+15551234567)
to_templatestring—Jinja2 template → recipient number (E.164)
message_templatestring—Jinja2 template → SMS body
retryobject | nullnullPer-destination retry override

One of account_sid / account_sid_env and one of auth_token / auth_token_env are required (enforced at config load).

Authentication​

Twilio uses HTTP Basic auth: the Account SID is the username and the auth token is the password. Find both in the Twilio Console. Store them in env vars:

export TWILIO_ACCOUNT_SID="ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export TWILIO_AUTH_TOKEN="your-auth-token"

Requests go to https://api.twilio.com/2010-04-01/Accounts/<SID>/Messages.json.

Common Patterns​

Recipient from a source column (must already be E.164):

to_template: "{{ row.phone_e164 }}"

Conditional body with Jinja2:

message_template: >
{% if row.status == 'shipped' %}Your order shipped!{% else %}Order received.{% endif %}

Notes​

  • (core) — no extra install required.
  • Both from_number and the rendered to_template must be E.164 (+<country><number>, no spaces or dashes) or Twilio rejects the message.
  • One API call per row. SMS is billed per message — use --dry-run to preview the rendered recipients/bodies before a real run.
  • Per-row send failures (invalid number, unsubscribed recipient) are recorded in result.row_errors; on_error: skip continues the batch.
  • For high volume, set rate_limit.requests_per_second to match your Twilio account's messaging throughput.

Rate limiting​

Vendor limit: throughput is provisioned, not a flat API cap — a long-code US number sends ~1 message/second (MPS) by default; short codes and messaging services are much higher. Match your account's actual MPS. drt applies no automatic cap here — set one explicitly:

destination:
type: twilio
from_number: "+15551234567"
rate_limit:
requests_per_second: 1
burst: 5 # optional: allow a short catch-up burst after idle time

destination.rate_limit beats sync.rate_limit, which beats the default of 10/s.

The limiter is shared per account (the account SID), not per sending number — the quota follows the account. Several syncs sending under one account concurrently (drt run --threads 4) pace through one bucket instead of one bucket each. When they request different rates, the lowest wins for both.

References​