Skip to content

SMS and voice relay

A self-hosted install needs its own Twilio account to page people by SMS and phone call. The relay removes that step: a Argavon server that has Twilio (such as Argavon Cloud) sends the SMS and calls for your install, and reports back what happened. You hold a relay key; the relay's operator gives it to you.

Everything else about paging stays the same. Delivery reports, voicemail detection, the phone keypad (1 acknowledges, 2 escalates, 9 repeats), repeat calls through Do-Not-Disturb and moving on to your next contact method all work as they do with your own Twilio account.

What leaves your install

Only what is needed to page someone:

  • the phone number of the person being paged or verified,
  • the text of the SMS, or the words the call reads out (the incident's severity, service and title, or a verification code),
  • the address on your install that the relay reports back to.

Nothing else goes to the relay: no alerts, no incident history, no names or email addresses. The relay keeps the last four digits of each number and does not keep the text. It keeps a record of each relayed SMS or call (time, channel, Twilio's status) for 30 days, and counts them per key and month.

Set up an install to use the relay

Set these on your install and restart it:

Setting Value
RELAY_URL The relay's address, such as https://relay.example.com
RELAY_KEY The key you were given, rk_<id>.<secret>. Treat it like a password.
RELAY_CALLBACK_BASE Your install's public https:// address. Defaults to FRONTEND_ORIGIN when that is https://.

Leave the TWILIO_* settings empty. When TWILIO_ACCOUNT_SID is set, the install uses Twilio directly and ignores the relay.

After the restart, SMS and Phone call appear in the contact method types, and people verify their numbers as usual.

The relay must be able to reach RELAY_CALLBACK_BASE for delivery reports and the keypad. Without it, a relayed page counts as sent once the relay accepts it, nobody can acknowledge from the keypad, and unanswered calls are not repeated.

Two things differ from your own Twilio account:

  • The calls and SMS come from the relay's number, so the contact card (/api/v1/me/pager-contact.vcf) does not list it. Ask the relay's operator for the number if you want to add it to your phone.
  • Each key has a monthly allowance. When it is used up, SMS and call deliveries fail with a clear reason and your other methods (push, email, Slack, Teams, webhooks) still work. The allowance starts again on the first of the month (UTC).

Run a relay

A relay is a Argavon server with Twilio configured and RELAY_ENABLED=true. Set TWILIO_CALLBACK_BASE to its public address so Twilio can report delivery and keypresses. Without Twilio the server does not start with RELAY_ENABLED=true.

Platform operators (the addresses in PLATFORM_ADMIN_EMAILS) manage keys:

Request What it does
POST /api/v1/platform/relay-keys Create a key: {"name": "acme install", "monthly_quota": 1000}. The answer has key; it is shown this once.
GET /api/v1/platform/relay-keys Every key with used_this_month, monthly_quota, last_used_at and revoked_at. Never the key.
DELETE /api/v1/platform/relay-keys/{id} Revoke a key. Its install can no longer send. Reports of calls made before the revoke still reach the install.

monthly_quota is the number of SMS and calls together, 1 to 1000000 (1000 when left out). The relay stores the SHA-256 of the key's secret, sealed with MASTER_ENCRYPTION_KEY when that is set, and never the key itself. A lost key cannot be shown again: revoke it and create a new one.

API for installs

An install sends one request per SMS or call. Installs do this for you; this section is for people writing their own client.

POST /api/v1/relay/messages

{
  "to": "+14155550100",
  "channel": "voice",
  "text": "This is Argavon. You are being paged for a critical incident on api: DB down.",
  "keypad": true,
  "callback_url": "https://pager.example.com/api/v1/hooks/relay/<workspace>/<delivery>",
  "idempotency_key": "<delivery id>"
}
  • channel is sms or voice. text is at most 480 bytes for an SMS and 800 for a call.
  • keypad (calls only) reads the choices after the text: 1 acknowledge, 2 escalate, 9 repeat. It needs callback_url.
  • callback_url is optional and must be a public https:// address (plain http and private addresses only when the relay sets NOTIFY_ALLOW_PRIVATE_TARGETS=true). Without it there are no reports.
  • idempotency_key is required. A second request with the same key is answered from the first (200, "duplicate": true) and nothing is sent again, so retries and replayed requests never page twice.

Every request is signed with the key:

Header Value
X-Relay-Key-Id The part of the key before the dot, rk_<id>
X-Relay-Timestamp Unix seconds. Refused when more than 5 minutes from the relay's clock.
X-Relay-Signature v1= and the hex HMAC-SHA256 of <timestamp>.<body>, keyed with the hex SHA-256 of the secret (the part after the dot)

Answers:

Status Code Meaning
201 Sent: id, status, used_this_month, monthly_quota
200 Already sent with this idempotency_key; "duplicate": true
400 INVALID_INPUT A field is wrong or unknown
401 RELAY_UNAUTHORIZED Unknown or revoked key, bad signature, or a timestamp out of range
402 RELAY_QUOTA_EXCEEDED The key's month is used up
404 RELAY_DISABLED This server does not run a relay
409 RELAY_IN_FLIGHT The same idempotency_key is being sent right now; try again
422 RELAY_REFUSED Twilio refused the message (for example, the number). It does not count.
502 RELAY_UPSTREAM Twilio could not be reached. It does not count; try again.

What the relay sends back

The relay posts each Twilio report and each keypress to callback_url, signed the same way with the same key. The install checks the key id, the signature, the timestamp, and that idempotency_key names the delivery in the URL.

A report:

{"event": "status", "message_id": "rm_…", "idempotency_key": "<delivery id>",
 "provider_id": "CA…", "status": "in-progress", "outcome": "delivered", "answered_by": "human"}

outcome is delivered, not_delivered, or empty while nothing is final. Answer 204; a 5xx makes Twilio send the report again.

A keypress:

{"event": "keypad", "message_id": "rm_…", "idempotency_key": "<delivery id>", "digits": "1"}

Answer 200 with what the call does next: {"say": "The incident is acknowledged. Thank you. Goodbye."} reads the line and hangs up, and {"replay": "<the page text>"} reads the page and the choices again. The relay builds the call's script from that answer; an install cannot make the relay's calls do anything else.