Skip to main content
Twilio sends a webhook when a call arrives. Rapida responds with TwiML that opens a bidirectional Media Stream (WebSocket) carrying μ-law 8kHz audio.

Vault Credentials

In the Rapida dashboard go to Credentials → Create Credential, select provider type Twilio:
KeyDescription
account_sidTwilio Account SID (ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
account_tokenTwilio Auth Token

Setup

1

Set PUBLIC_ASSISTANT_HOST

PUBLIC_ASSISTANT_HOST is the public HTTPS hostname Twilio will use to reach your server — for webhooks and the WebSocket media stream.
Set it to your server’s public domain in docker/assistant-api/.assistant.env:
PUBLIC_ASSISTANT_HOST=your-server.com   # no https:// prefix
Also update connection.media in ui/src/configs/config.production.json:
{
  "connection": {
    "media": "https://your-server.com"
  }
}
2

Configure the Twilio phone number webhook

In Twilio ConsolePhone Numbers → Manage → Active numbers, select your number:
FieldValue
A call comes inWebhook, HTTP POST
URLhttps://{PUBLIC_ASSISTANT_HOST}/v1/talk/twilio/call/{assistantId}?x-api-key={apiKey}
Status callback URLhttps://{PUBLIC_ASSISTANT_HOST}/v1/talk/twilio/ctx/{contextId}/event?x-api-key={apiKey}
Replace {assistantId} with the numeric assistant ID from the Rapida dashboard.
3

Attach vault credential to the assistant

In the assistant’s Phone Deployment, select the Twilio vault credential you created.
4

Verify

# Check the tunnel is proxying correctly
curl https://{PUBLIC_ASSISTANT_HOST}/readiness/
# Expected: {"status":"ok"}
You can monitor Twilio webhook requests in real time at http://localhost:4040 (ngrok inspector) or in the Twilio Console under Monitor → Logs → Calls.
PUBLIC_ASSISTANT_HOST must be HTTPS. Twilio rejects plain HTTP webhook URLs and ws:// WebSocket connections — always use https:// for the webhook URL and wss:// for the media stream (Rapida handles this automatically).

What Rapida Returns

When Twilio hits the inbound webhook, Rapida responds with TwiML connecting a Media Stream:
<Response>
  <Connect>
    <Stream url="wss://{PUBLIC_ASSISTANT_HOST}/v1/talk/twilio/ctx/{contextId}?x-api-key={apiKey}"
            name="{assistantId}__{conversationId}"
            statusCallback="https://{PUBLIC_ASSISTANT_HOST}/v1/talk/twilio/ctx/{contextId}/event?x-api-key={apiKey}"
            statusCallbackEvent="initiated ringing answered completed">
      <Parameter name="assistant_id" value="{assistantId}"/>
      <Parameter name="client_number" value="{callerNumber}"/>
    </Stream>
  </Connect>
</Response>

Outbound Calls

Rapida calls client.Api.CreateCall via the Twilio Go SDK. The StatusCallback, StatusCallbackEvent, and Twiml are constructed automatically from PUBLIC_ASSISTANT_HOST. No additional configuration is required beyond the vault credential.

Audio Spec

PropertyValue
Encodingμ-law (PCMU) 8-bit
Sample rate8000 Hz
ChannelsMono
TransportBase64-encoded JSON frames (Media Streams spec)

Vonage

Global PSTN alternative with higher audio quality

Exotel

India / SEA PSTN

Telephony Overview

All providers and URL routing reference

Configuration

Full env var reference