If you know Twilio, you're probably familiar with their powerful cloud communications platform. With Vocals, you can easily connect your Twilio phone number to an AI conversational agent that handles phone calls autonomously.
This tutorial shows you how to connect your Twilio phone number to a Vocals AI agent for voice communication, using Twilio to handle phone calls. By the end of this guide, you'll have a working integration that can receive inbound calls on a Twilio number and route them to your Vocals agent, as well as make outbound calls.
Prerequisites
Before you begin, make sure you have the following:
- A Twilio account — Sign up with Twilio for free here
- A Twilio number with voice capability — Read the docs here on how to obtain a Twilio number
- A Vocals account — Sign up here
What You'll Build
This voice application will route all inbound calls from your Twilio number to your Vocals agent using Vocals' native Twilio integration. You'll also be able to make outbound calls through Twilio's REST API directly from the Vocals dashboard.
You'll start by creating a voice agent in Vocals, then import your Twilio account credentials, add your phone number, and link it to your agent. If you don't have an agent available to use, we'll show you how to set one up.
Create a Vocals Agent
Once you're signed into Vocals, head over to the Agents section in the dashboard.
Click on Create Agent and configure the following:
- Name: Give your agent a descriptive name (e.g., "Customer Support Assistant").
- System Instructions: Define your agent's personality and behavior. For example: "You are a friendly phone assistant that helps customers with their inquiries."
- STT Provider: Select the speech recognition engine (e.g., Deepgram, OpenAI Whisper).
- LLM Provider: Choose the language model (e.g., OpenAI GPT-4, Anthropic Claude).
- TTS Provider: Select the voice synthesizer (e.g., ElevenLabs, OpenAI TTS).
If you already have an agent created, you can skip this step and use it directly.
Add Twilio Number and Credentials to Vocals
Now that you've created an agent for your voice application, the next step is to integrate it with your Twilio number. First, you'll need to fetch your Twilio credentials.
Fetch your Twilio Credentials
Open a new tab, head over to your Twilio Console and scroll down to the Account Info section to locate your Account SID and your Twilio phone number.
Twilio Console Credentials
| Account SID | ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|---|
| Auth Token | (click "Show" to reveal and copy) |
Add credentials in Vocals
Navigate back to your Vocals dashboard and head over to SIP Providers in the sidebar menu. Click Add Provider and select the "Twilio" type. Enter your credentials:
Twilio Provider Configuration in Vocals
| Name | Twilio (or any descriptive name) |
|---|---|
| SIP Type | Twilio |
| Account SID | Your Twilio Account SID |
| Auth Token | Your Twilio Auth Token |
Now you need to manually configure the voice webhook in your Twilio account. Go to Twilio Console → Phone Numbers → your number → Voice Configuration and in the "A call comes in" field, select Webhook, method HTTP POST, and paste the following URL:
Connect Vocals Agent to your Twilio Number
Once your credentials have been imported, add your Twilio phone number in the Phone Numbers section of the SIP provider you just created. Enter the number in E.164 format (e.g., +14155551234 or +34951XXXXXX).
The next step is to link your newly added number with your Vocals agent. In the Phone Numbers section of the dashboard, select your Twilio number and choose the voice agent you want to handle calls from the agent dropdown.
Test your Integration
You can test your integrated agent through either an outbound call or an inbound call.
For an inbound call: Simply call your Twilio phone number from any phone and you'll be connected to your Vocals agent.
For an outbound call: In the Vocals dashboard, navigate to the Calls section, select your agent and Twilio number as the source, enter the destination number, and click Start Call.
In both cases, you'll be able to see the detailed call log with the full transcription in the Calls section of the dashboard.
What's Next?
You've successfully built a voice integration that connects your Twilio phone number to a Vocals AI agent! Now that you have a working agent linked to your Twilio phone number, you can enhance your agent's capabilities further:
- Customize the voice: Experiment with different TTS providers and voices to find the one that best fits your brand.
- Configure webhooks: Connect webhooks to send call data to your CRM, database, or other tools in real time.
- Enable Voice SDK: If you need human agents to make calls from the browser, you can optionally configure Twilio's Voice SDK in Vocals with an API Key and a TwiML App.
- Monitor and optimize: Use the Vocals dashboard analytics to review transcriptions, call duration, and agent performance metrics.
- Scale: Add more Twilio numbers from different countries and assign specialized agents to each one.