Make sure you've completed the steps described in the Twilio Setup documentation before proceeding!
In order for your Retool app to authenticate with Twilio, you'll need to get a valid chat token. To set this up:
- Navigate to the
/resources
page in your instance and click "Create a new resource." - Select REST API as the resource type.
- Name the resource “Twilio Conversations Chat Token”.
- Specify the URL of your
chat_token
function as noted in step six of the Twilio setup. - Specify a header with a key of
identity
and a value of{{current_user.email}}
. This is used to pass the email address of the Retool user to Twilio for use in the token identity. - Save your changes.
Your Retool app will need to delete previously created Conversations in order to start new Conversations with the same SMS number, as well as add new participants to the Conversation. To set this up:
- Navigate to the
/resources
page in your instance and click "Create a new resource". - Select Twilio as the resource type.
- Name the resource "Twilio Conversations API".
- Specify your Twilio API Key SID as the value of
Account SID
and your Twilio API Key Secret as the value ofAuth Token
.- These credentials were created in Step 2 of the Twilio Setup.
- The current version the Twilio resource doesn't correctly validate API Keys, so the "test connection" button won't work on the Resource configuration screen.
- Save your changes.
Download twilio-conversations-retool-app.json from this repository.
On the Retool main page, click Create new
and select Import an app
. Upload the JSON file containing the app code, and name the app.
You may need to connect the Resource Queries in the Retool app with the Resources you created in the previous steps:
Folder | Resource Query | Resource |
---|---|---|
gets | getChatToken | Twilio Conversations Chat Token |
gets | getConversations | Twilio Conversations API |
writes | addParticipant | Twilio Conversations API |
writes | deleteConversations | Twilio Conversations API |
If everything is working as expected, you should now be able to send and receive messages between the Retool app and the phone number you registered! To use the app:
- When first loading the app, you'll be prompted to enter your Twilio Conversations Service SID. This is the Service SID you retrieved in step 3 of the Twilio setup.
- Once the app has initialized, fill out the SMS settings:
- Enter the phone number you were assigned in step 0 of the Twilio setup as "Twilio Outbound number".
- Enter the SMS-enabled phone number that you verified in step 1 of the Twilio setup as "Customer number" and click Submit.
- Enter some text in the chat box and press "enter" to send!
You can read more about Retool custom components. You can also view the code used in the Twilio Conversations component in Retool, the contents of which are included in retool-custom-component.html for easy reading!
Also, check out our in-depth video walkthrough of how this app is put together!