Overview
TelemanAI integrates with Twilio to power voice calls and SMS campaigns. This integration enables you to:- Make outbound voice calls through Twilio
- Send SMS messages
- Configure SIP trunks for advanced call routing
- Track call costs and usage
Prerequisites
Before you begin, ensure you have:- A Twilio account (Sign up here)
- Your Twilio Account SID and Auth Token
- At least one Twilio phone number
Configuration Steps
Get Twilio Credentials
- Log in to your Twilio Console
- From the dashboard, locate your Account SID and Auth Token
- Copy these credentials for the next step
Keep your Auth Token secure. Never share it publicly or commit it to version control.
Purchase a Phone Number
If you don’t have a Twilio phone number:
- Go to Phone Numbers → Buy a Number in the Twilio Console
- Select a number with Voice and SMS capabilities
- Complete the purchase
- Add the number to your
.envfile asTWILIO_NUMBER
Configure Webhooks (Optional)
To receive call status updates and handle inbound calls:
- In Twilio Console, go to your phone number settings
- Under Voice & Fax, set:
- A CALL COMES IN:
https://your-domain.com/api/twilio/voice - METHOD: POST
- A CALL COMES IN:
- Under Messaging, set:
- A MESSAGE COMES IN:
https://your-domain.com/api/twilio/sms - METHOD: POST
- A MESSAGE COMES IN:
Replace
your-domain.com with your actual TelemanAI installation domain.SIP Trunk Configuration
For advanced call routing and better call quality, configure a SIP trunk:Create SIP Trunk in Twilio
- Navigate to Elastic SIP Trunking in Twilio Console
- Click Create new SIP Trunk
- Enter a friendly name
- Configure Origination settings with your server IP
- Configure Termination settings for outbound calls
- Save the configuration
Testing the Integration
Verify Credentials
Run the configuration test:This command verifies your Twilio credentials are valid.
Environment Variables Reference
| Variable | Description | Required | Example |
|---|---|---|---|
TWILIO_ACCOUNT_SID | Your Twilio Account SID | Yes | AC085429e8d240706a... |
TWILIO_AUTH_TOKEN | Your Twilio Auth Token | Yes | f528f37ca76b821f21... |
TWILIO_NUMBER | Your Twilio phone number | Yes | +1234567890 |
TWILIO_APP_SID | Twilio Application SID (for SIP) | No | AP... |
SIP_TRUNK | Enable SIP trunk functionality | No | YES or NO |
TWILIO_SIP_ENABLED | Enable SIP calls | No | true or false |
TWILIO_SIP_DEFAULT_DOMAIN | Your SIP domain | No | domain.pstn.twilio.com |
TWILIO_SIP_SECURE | Use secure SIP (SIPS) | No | true |
TWILIO_SIP_DEFAULT_AUTH_TYPE | Authentication type | No | IP_ACL or CREDENTIAL_LIST |
TWILIO_SIP_VOICE_URL | Voice webhook URL | No | https://... |
TWILIO_SIP_LOGGING | Enable call logging | No | true |
Troubleshooting
Authentication Failed Error
Authentication Failed Error
Problem:
HTTP 401 - Authentication failedSolution:- Verify your Account SID and Auth Token are correct
- Check for extra spaces in your
.envfile - Ensure you’re using the correct credentials (not test credentials in production)
Unable to Create Call
Unable to Create Call
Problem: Calls fail to connectSolution:
- Verify your Twilio phone number is active
- Check that you have sufficient balance in your Twilio account
- Ensure the destination number is in a valid format (E.164 format recommended)
- Check Twilio’s debugger for detailed error messages
SIP Trunk Not Connecting
SIP Trunk Not Connecting
Problem: SIP trunk shows as offlineSolution:
- Verify your server’s IP is whitelisted in the IP ACL
- Check that firewall rules allow SIP traffic (ports 5060-5061)
- Ensure your SIP domain is correctly configured
- Test connectivity using Twilio’s SIP trunk debugger
Webhook Not Receiving Events
Webhook Not Receiving Events
Problem: Call status updates not receivedSolution:
- Verify your webhook URL is publicly accessible
- Check that your SSL certificate is valid
- Ensure your server is not blocking Twilio’s IP ranges
- Review Twilio’s webhook logs in the Console
Cost Tracking
TelemanAI automatically tracks Twilio call costs. To view cost reports:- Navigate to Analytics → Call Costs
- View detailed cost breakdowns by campaign
- Export reports for billing purposes
Call costs are fetched from Twilio’s API and updated in real-time.
Next Steps
Create Voice Campaign
Learn how to create your first voice campaign
SMS Marketing
Set up SMS campaigns with Twilio
Call Analytics
Track and analyze call performance
Advanced Routing
Configure advanced call routing rules