Skip to main content

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

1

Get Twilio Credentials

  1. Log in to your Twilio Console
  2. From the dashboard, locate your Account SID and Auth Token
  3. Copy these credentials for the next step
Keep your Auth Token secure. Never share it publicly or commit it to version control.
2

Configure Environment Variables

Add your Twilio credentials to the .env file:
TWILIO_ACCOUNT_SID="AC085429e8d240706a0826fff4674535d3"
TWILIO_AUTH_TOKEN="your_auth_token_here"
TWILIO_NUMBER="+1234567890"
Replace the example values with your actual Twilio credentials.
3

Purchase a Phone Number

If you don’t have a Twilio phone number:
  1. Go to Phone NumbersBuy a Number in the Twilio Console
  2. Select a number with Voice and SMS capabilities
  3. Complete the purchase
  4. Add the number to your .env file as TWILIO_NUMBER
4

Configure Webhooks (Optional)

To receive call status updates and handle inbound calls:
  1. In Twilio Console, go to your phone number settings
  2. Under Voice & Fax, set:
    • A CALL COMES IN: https://your-domain.com/api/twilio/voice
    • METHOD: POST
  3. Under Messaging, set:
    • A MESSAGE COMES IN: https://your-domain.com/api/twilio/sms
    • METHOD: POST
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:
1

Enable SIP Trunk

Update your .env file:
SIP_TRUNK="YES"
TWILIO_SIP_ENABLED=true
TWILIO_SIP_SECURE=true
2

Configure SIP Domain

Set up your SIP domain configuration:
TWILIO_SIP_DEFAULT_DOMAIN="your-sip-domain.pstn.twilio.com"
TWILIO_SIP_DEFAULT_AUTH_TYPE="IP_ACL"
TWILIO_SIP_VOICE_URL="https://your-domain.com/api/sip/inbound"
TWILIO_SIP_LOGGING=true
3

Create SIP Trunk in Twilio

  1. Navigate to Elastic SIP Trunking in Twilio Console
  2. Click Create new SIP Trunk
  3. Enter a friendly name
  4. Configure Origination settings with your server IP
  5. Configure Termination settings for outbound calls
  6. Save the configuration
4

Configure Authentication

Choose your authentication method:IP Access Control List (Recommended):
  • Add your server’s public IP address to the IP ACL
  • More secure for production environments
Credential List:
  • Create username/password credentials
  • Useful for dynamic IP environments

Testing the Integration

1

Verify Credentials

Run the configuration test:
php artisan twilio:test
This command verifies your Twilio credentials are valid.
2

Make a Test Call

  1. Navigate to Campaigns in TelemanAI
  2. Create a new voice campaign
  3. Add a test contact
  4. Launch the campaign
  5. Verify the call is placed successfully

Environment Variables Reference

VariableDescriptionRequiredExample
TWILIO_ACCOUNT_SIDYour Twilio Account SIDYesAC085429e8d240706a...
TWILIO_AUTH_TOKENYour Twilio Auth TokenYesf528f37ca76b821f21...
TWILIO_NUMBERYour Twilio phone numberYes+1234567890
TWILIO_APP_SIDTwilio Application SID (for SIP)NoAP...
SIP_TRUNKEnable SIP trunk functionalityNoYES or NO
TWILIO_SIP_ENABLEDEnable SIP callsNotrue or false
TWILIO_SIP_DEFAULT_DOMAINYour SIP domainNodomain.pstn.twilio.com
TWILIO_SIP_SECUREUse secure SIP (SIPS)Notrue
TWILIO_SIP_DEFAULT_AUTH_TYPEAuthentication typeNoIP_ACL or CREDENTIAL_LIST
TWILIO_SIP_VOICE_URLVoice webhook URLNohttps://...
TWILIO_SIP_LOGGINGEnable call loggingNotrue

Troubleshooting

Problem: HTTP 401 - Authentication failedSolution:
  • Verify your Account SID and Auth Token are correct
  • Check for extra spaces in your .env file
  • Ensure you’re using the correct credentials (not test credentials in production)
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
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
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:
  1. Navigate to AnalyticsCall Costs
  2. View detailed cost breakdowns by campaign
  3. 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

Additional Resources

Build docs developers (and LLMs) love