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

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.

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:

curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls.json" \
--data-urlencode "Url=$TWIML_BIN_URL" \
--data-urlencode "To=+15558675310" \
--data-urlencode "From=+15552223214" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

or use the twilio-cli:

twilio api:core:calls:create --from="+15552223214" --to="+15558675310" --url="$TWIML_BIN_URL"