Twilio WebSocket Transport
Native support for Twilio’s WebSocket Transport with Daily Bots
Twilio’s WebSocket offers an alternative transport protocol to Real-time Transport Protocol (RTP). The WebSocket carries Twilio’s bidirectional Media Streams that allow third parties to send and receive audio from Twilio. While we recommend WebRTC over WebSockets, by placing Daily Bots infrastructure close to Twilio’s Voice servers, the underlying issues of TCP are mitigated.
Alternatively, Twilio Voice users can connect to third-party over SIP. In this case, by using Twilio’s WebSockets, we have removed the additional latency hops to perform SIP interconnect.
Configuration on Daily Bots
You have two options to configure your Daily Bots: either through the dashboard or via the REST API.
Dashboard
To get started, create a Twilio Bot Configuration on the dashboard.
As part of the Bot set up, config
needs to contain the LLM prompt
, LLM settings and the corresponding text-to-speech voice settings.
This will return a Bot ID
, a unique identifier that encapsulates the unique config for a Daily Bot that you can map to on Twilio via the TwiML.
REST API
Alternatively, you can use the REST API to create a Twilio Bot Configuration. This approach is particularly useful for automation and programmatic bot management.
First, create a new Twilio bot configuration by sending a POST request to the /twilio-config
endpoint:
The API will respond with configuration details including a twiml field that contains the TwiML needed for your Twilio configuration:
Copy the twiml
value from the response - you’ll need this for the Twilio console setup described in the next section.
You can also manage your configurations using additional endpoints. See the API reference for more information.
Configuration on Twilio
Now head over to the Twilio console to create a TwiML Bin. TwiML Bins are Twilio-hosted instructions for your Twilio phone number.
In your TwiML Bin, you’ll see a text area called TWIML
. In this text area, paste the TwiML created for your Daily Bot. You can find this TwiML in the Daily Bots dashboard > Phones > Twilio bot configuration.
The TwiML contains the Stream URL, i.e., the WebSocket gateway for Daily’s Twilio Transport and Daily-specific <Parameters>
that are used to identify your account and your unique Bot ID.
Once the TwiML bin is stored, you can assign this TwiML to your phone number in the Twilio console.
You are now ready to test dial-in and dial-out with Daily Bots and your Twilio phone number using Twilio’s WebSocket Transport.
To dial in, just dial the Twilio phone number and it will connect you to the bot. To dial out, you can call the Twilio REST API with To
, From
and the TwiML Bin url
. For example the curl command is:
or use the twilio-cli: