# Twilio Integration

> Configure Twilio for voice communication in Lemu AI

URL: https://docs.lemuai.com/integrations/telephony/twilio

## Overview

Twilio is a cloud communications platform that enables voice calling, messaging, and video capabilities. Lemu AI's Twilio integration provides seamless connectivity for your voice agents.

## Prerequisites

Before setting up Twilio integration, you'll need:

- A [Twilio account](https://www.twilio.com/try-twilio)
- Account SID and Auth Token from your Twilio Console
- At least one Twilio phone number

## Video Tutorial

Watch this step-by-step guide to set up Twilio with Lemu AI:

<iframe
  className="w-full aspect-video rounded-xl"
  src="https://www.tella.tv/video/cmgbvzkrt00jk0clacu16blm3/embed?b=1&title=1&a=1&loop=0&t=0&muted=0&wt=1"
  title="Lemu Twilio Setup"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  allowFullScreen
></iframe>

## Configuration

### Step 1: Get Twilio Credentials

1. Log in to your [Twilio Console](https://console.twilio.com/)
2. Find your **Account SID** and **Auth Token** on the dashboard
3. Navigate to **Phone Numbers** → **Manage** → **Active Numbers**
4. Copy your phone number(s)

### Step 2: Configure in Lemu AI

1. Go to **Agent Setup → Telephony** in the sidebar
2. Watch the Twilio setup video tutorial above for detailed guidance
3. Select **Twilio** as your provider

![Telephony configuration showing the Twilio provider selected](https://docs.lemuai.com/images/lemu-telephony-config.png)
4. Enter your credentials:
   - Account SID
   - Auth Token
   - From Phone Number (with country code, e.g., +1234567890)
5. Click **Save Configuration**

### Step 3: Test Your Configuration

1. Create a test workflow
2. Click "Test Call" to verify connection
3. Check call logs for successful connection

## Inbound Calling Setup

To enable inbound calling with Twilio:

1. **Complete Telephony Configuration**: Use the same [Configuration](#configuration) steps above
2. **Get Your Workflow Webhook URL**: Find your workflow ID and construct the webhook URL as: `https://app.lemuai.com/api/v1/telephony/inbound/{workflow_id}`

### Configure Webhook in Twilio Console

1. **Configure Phone Number Webhook**:
   - Go to **Phone Numbers** → **Manage** → **Active Numbers** in Twilio Console
   - Click on the phone number you want to use for inbound calls
   - In the "Voice Configuration" section:
  - Set **Webhook** to: `https://app.lemuai.com/api/v1/telephony/inbound/{workflow_id}`
  - Set **HTTP Method** to: `POST`
   - Click **Save Configuration**

   **Note:** Replace `{workflow_id}` with your actual workflow ID.

   <img
  src="/images/twilio-inbound-config.png"
  alt="Twilio phone number voice configuration showing webhook URL setup for inbound calls"
   />

2. **Verify Setup**:
   - Verify any firewalls allow Twilio's IP ranges

### Test Inbound Calling

1. Call your configured Twilio phone number from another phone
2. Verify your Lemu AI voice agent answers and responds
3. Check call logs in both Lemu AI dashboard and Twilio Console

## Troubleshooting

  **Invalid phone number error**

  Ensure phone numbers include country code in E.164 format: `+1234567890`
  
  
  **Authentication failed**

  - Verify Account SID and Auth Token are correct
  - Check for extra spaces in credentials
  - Ensure credentials haven't been regenerated in Twilio Console
  
  
  **Webhook signature validation failing**

  - Confirm your Auth Token matches exactly
  - Verify the webhook URL matches what Twilio sends
  - Check if you're behind a proxy that modifies requests
  
  
  **No audio on calls**

  - Verify WebSocket connection is established
  - Check firewall rules for WebSocket traffic
  - Ensure audio pipeline is configured correctly
  
  
  **Inbound calls go to voicemail**

  - Verify webhook URL is correctly configured in Twilio Console
  - Check the webhook URL was pasted exactly, with no spaces or missing characters
  - Check that phone number is properly linked to webhook
  
  
  **Voice agent doesn't respond to inbound calls**

  - Confirm voice agent workflow is properly configured
  - Check webhook signature validation is working
  - Verify WebSocket connection establishes successfully
  - Review call logs for error messages
  

## Best Practices

- Store credentials securely in the database
- Test your configuration with a single call before running campaigns
- Monitor Twilio Console for usage and billing
