Dial-in: WebRTC (Twilio + Daily)
Call your Pipecat bot using Daily WebRTC and a Twilio phone number
Things you’ll need
- An active Twilio developer key.
- One or more Twilio provisioned phone numbers (covered below).
- The Twilio Python client library (
pip install twilio
).
Prefer to look at code? See the example project!
We have a complete dialin-ready project using Daily as both a transport and Twilio as a phone provider in the Pipecat repo. This guide references the project and steps through the important parts that make dial-in work.
Getting a phone number
- Visit console.twilio.com and purchase a new phone number (or via the API.)
- Ensure your purchased number supports Voice capabilities.
- Ensure your purchased number appears in your ‘active numbers’ list.
Project setup
You’ll need to set two environment variables for your project: TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
, value for which you can obtain via the Twilio console.
Configuring your bot runner
You’ll need a HTTP service that can receive incoming call hooks and trigger a new agent session. We discussed the concept of a bot runner in the deployment section, which we’ll build on here to add support for incoming phone calls.
Within the start_bot
method, we’ll setup the Twilio client like so:
Creating a new SIP-enabled room
We’ll need to configure the Daily room to be setup to receive SIP connections. daily-helpers.py
as part of the Pipecat service, has some useful imports that make this easy. We just need to pass through new SIP parameters as part of room creation:
Setup the Twilio webhook on your phone number
Twilio needs to know where our start_bot
URL is located as a webhook which it can trigger when a user dials a phone number. You can do this via the Twilio console or via the Twilio API:
If you want to test locally, you can expose your web method using a service such as ngrok.
A quick test
With the webhook configured, you should now be able to dial your Twilio number and trigger the start_bot
URL on your bot runner.
Assuming your webhook is configured correctly, we now need to configure our bot to signal to Twilio when it is ready for the call to be forwarded.
Configuring your Pipecat bot
Let’s take a look at bot_twilio.py
and step through the configuration.
First, it’s setup to receive additional command line parameters which are passed through to the DailyTransport
object: