Before you can get this Retool app working, you'll need to do some pre-work in Twilio.
If you don't already have a Twilio account, you'll need to get one! The good news is that Twilio makes it easy (and free!) to get started. Just head over to https://www.twilio.com/try-twilio and sign up!
As you go through the onboarding flow, indicate that you'll be building a voice app. Once you're logged into Twilio console, you'll be prompted to get a Twilio phone number. Note the phone number you were assigned for later!
A TwiML Application tells Twilio how to handle the calls you'll make from your Retool app. Specify a name for your TwiML app and note the TwiML App SID
for later. Leave all other settings blank, we'll fill them in later on!
Create an API key and note the key's SID
and Secret
for later.
A Twilio Service is a container for the server-less functions which make it possible for your Retool app to get a voice access token, and for outbound calls to be routed correctly.
In your new Twilio Service, set the following environment variables:
Key | Value |
---|---|
TWIML_APPLICATION_SID |
The TwiML App SID you noted in step one |
API_KEY_SID |
The API Key SID you noted in step two |
API_KEY_SECRET |
The API Key Secret you noted in step two |
CALLER_ID |
The phone number you noted in step zero. Make sure to include a + and the country code at the beginning! |
The server-less functions running in Twilio need access to a few software libraries to function properly. Import the following NPM modules:
Module | Version |
---|---|
lodash |
4.17.11 |
@twilio/runtime-handler |
1.2.3 |
twilio |
^3.77.3 |
xmldom |
0.1.27 |
util |
0.11.0 |
In order for the embedded Twilio dialer to authenticate with Twilio's services, it needs a valid access token. To create a function for issuing voice tokens:
- Add a function
- Specify a path
voice-token
- Set the function to
Public
.- Heads up! This means that anyone who can guess the URL of your function can issue valid access tokens. You would need to implement authentication on this endpoint for a production use-case!
- Copy and paste the contents of voice-token.js into the function and save
- Copy the URL for this function for later use
In order for Twilio to know what to do when it receives a call from your app, you need a call routing app. To create a call routing function:
- Add a function
- Specify a path
twiml-app
- Set the function to
Protected
- Copy and paste the contents of twiml-app.js into the function and save
- Copy the URL for this function for later use
This finalizes all of the changes you've made.
Remember that empty TwiML app we created in step one? Edit the app settings and provide the URL for your twiml-app
function as the value of the Voice Configuration Request URL. Specify a Request Method of HTTP POST
and save your changes.
This step connects inbound requests from your Retool app to the call routing function.
Next, set up the Retool app to make calls using your Twilio service!