Dial-in support
Daily Bots allows purchasing numbers directly via the dashboard and using them to call your bot via phone.
To get started, buy a number via the dashboard or using the curl commands.
Creating a dial-in route
Dial-in requires additional dialin_settings
properties that are passed to the Daily Bots /start
endpoint.
To accommodate this, we’ll create a new Next.js route in the api
directory:
We’re defining our config in the route directly, as dial-in bypasses the web
client. You can abstract this into a separate file (e.g. rtvi.config.ts
) if
you prefer, allowing you to use the same config for both dial-in and web.
Externally exposing your new route in local development
Since we’re working locally, we’ll need create a publically accessible URL for Daily to connect when a person dials the number.
We’ll use ngrok to create a tunnel to our local server by running the following in our terminal:
Your Next.js server may be running on a different port than 3000. Update the command accordingly.
This will give us a publically accessible https URL that points to our local server.
Remember to update the URL your number points outside of local development.
Configure via the Daily Bots dashboard
Navigate to the dashboard and click on the plus icon next to the number you purchased. A modal will open, select Self-hosted: provide a webhook URL. You’ll then see a field to enter a webhook URL:
Enter your ngrok URL (e.g. https://123.ngrok.app/api/dialin
) and click Save
.
Configuring via REST
If you’d prefer to do this programmatically, Daily provides a REST API, pinless_dialin
for configuring your purchased number.
Let’s point it at our newly created ngrok tunnel URL:
pinless_dialin
is an array that can contain forwarding rules for several phone_numbers
. These phone numbers can map to the same room_creation_api
or different URLs.
If you have configured multiple phone numbers, make note that the all phone_numbers
should be present when updating a single phone_number
. The API does not do partial array updates, i.e., a POST request will override the existing pinless_dialin
array with the new value. Hence, to keep existing routes, you should them all.
Assuming all is well, you should receive a JSON response (and see a test webhook creation request arrive at the route.) In addition, when a call is received, the webhook $YOUR_NGROK_TUNNEL_URL/api/dialin
contains the dialin_settings
, which are passed to the /bot/start
. The dialin_settings
are:
The To
and From
denote your phone number and the caller’s number, respectively. The callId
and callDomain
are Daily internal identifiers that are used to connect the incoming call to the bot (which in the interim period is on hold and listening to hold_music
.)
Dialing in
Time to give our bot a call!
When you’re dialing from outside America, to avoid international carrier rates by your carrier, you can use Skype (or similar such service) to connect to the number you purchased.
Assuming all is well, you should hear the bot’s initial message and be able to interact with it.