Phone providers: Twilio and Telnyx¶
SMS and calls go through a phone provider. Twilio is the main one. Telnyx can be added as the backup, so a page still goes out when Twilio is down. Either can also be the only provider.
Step by step: Set up Twilio and Telnyx failover (Enterprise), which also covers the Reliability Center and a failover drill.
What each plan gets¶
| Plan | When Twilio fails |
|---|---|
| Free, Pro | The page is retried through Twilio with the usual backoff (up to 5 tries). If it never goes through, the page is marked failed in the delivery log. It never goes through Telnyx. |
| Enterprise | The same page is sent again through Telnyx at once, as a second attempt in the delivery log. |
On a self-hosted install the backup needs a license that includes phone.failover. Without it, pages
behave like Pro.
What counts as a failure¶
- Twilio answers the send with an error, a 5xx or a 429, or does not answer within 10 seconds.
- Twilio's delivery report says the SMS was
failedorundelivered, or the callfailed.
Busy, no answer and voicemail are not provider failures. They are handled as before: the person's next contact method comes forward, and an unanswered urgent call rings again from the same number.
A request Twilio refuses with a 4xx (a number that is not valid, or rejected credentials) is not sent again through Telnyx. Fix the setting instead: the server log says what Twilio answered.
No double pages¶
Each attempt is its own row in the delivery log, with the provider that sent it. The resend names the
attempt it replaces (failover_of). A resend is made once per attempt and provider, whatever reports come
in later.
If Twilio reports the first SMS delivered after all, the first attempt is marked delivered. A resend that has not gone out yet is cancelled; one that has gone out stays in the log, so you see both.
When a provider keeps failing¶
When a provider fails 3 times within 2 minutes, it is skipped for 10 minutes: Enterprise pages go straight to the backup. After the 10 minutes the next page tries it again. When a send through it works, it is back.
While a provider is down:
- workspace admins see a banner on the dashboard,
- the admins of every workspace that pages by phone get one notice on their email, browser push, chat or webhook contact methods (never by SMS or call), and one more when it is back,
- the public delivery record at
/deliverylists the outage, with when it started and ended.
The skip is kept in memory on each server, so each server finds out from its own sends. The outage itself
is kept in the database (phone_outages), so with several servers the notice goes out once.
Set up Telnyx¶
In the Telnyx portal:
- Buy a number that can send SMS and make calls.
- Create a messaging profile and add the number to it. Set its inbound webhook to
https://<your app>/api/v1/hooks/telnyx/smsif you want people to acknowledge by replying 1. - Create a TeXML application and set its method to POST. Calls run the same script as Twilio calls, sent with the call, so the application needs no script address of its own.
- Create an API key, and copy the public key that signs webhooks (Account settings, Keys and credentials).
Then set:
TELNYX_API_KEY=KEY...
TELNYX_FROM_NUMBER=+14155550177
TELNYX_ACCOUNT_SID=<your Telnyx account id, a UUID>
TELNYX_TEXML_APP_ID=<the TeXML application id>
TELNYX_PUBLIC_KEY=<base64 public key>
TELNYX_MESSAGING_PROFILE_ID=<optional>
TELNYX_CALLBACK_BASE=https://app.example.com # defaults to TWILIO_CALLBACK_BASE
PHONE_PROVIDERS=twilio,telnyx # the default when both are set
The server checks these at start and refuses to start with a half-set Telnyx, as it does for Twilio.
PHONE_PROVIDERS sets the order. With only one provider configured, it is that one. PHONE_PROVIDERS=telnyx
makes Telnyx the only provider.
Add the Telnyx number to people's contacts too: the contact card in the app lists both numbers, so Do-Not-Disturb lets either through. A repeat call always comes from the same provider as the first call.
Webhooks¶
Telnyx sends delivery reports to /api/v1/hooks/telnyx/status/<workspace>/<delivery>, keypresses to
/api/v1/hooks/telnyx/voice/<workspace>/<delivery>, and SMS sent to the number to
/api/v1/hooks/telnyx/sms. Each request must carry a valid telnyx-signature-ed25519 over
telnyx-timestamp, a | and the body, from the last 5 minutes; anything else gets 403.
Test it¶
Each provider is tested on its own by the delivery canary (see delivery record). The record shows a row per provider.