This Node.js application integrates Twilio's Voice API with the Retell SDK, allowing inbound calls to be routed through Retell's SIP endpoint. The project leverages Express.js to handle HTTP requests and sets up a Twilio Voice Webhook for processing inbound calls. The call is registered with Retell to obtain a call_id
, which is then used to route the call through Retell's SIP infrastructure.
-
Clone the Repository
git clone https://github.com/HamChowderr/TwilioNonElasticSIP.git cd TwilioNonElasticSIP
-
Install Dependencies
npm install express twilio retell-sdk
-
Configure API Keys
- Open
index.js
(or your server file) and insert your Retell API key in place ofInsert Your API Key
. - Replace
Enter Your Agent ID
with your Retell Agent ID.
- Open
-
Start the Server
node index.js
The server will start at
http://localhost:3000
. -
Set Up Twilio Webhook
- In your Twilio Console, configure your Twilio phone number to use
http://your-server-url/voice-webhook
as the Voice Webhook URL for handling inbound calls.
- In your Twilio Console, configure your Twilio phone number to use
-
Make an Inbound Call
- When a call is received, the application:
- Registers the call with Retell, capturing the call ID.
- Creates a TwiML response to forward the call to Retell's SIP endpoint using the generated
call_id
. - Returns the response to Twilio, which completes the forwarding process.
- When a call is received, the application:
index.js
: Main application file, handling inbound calls via Twilio's Voice Webhook and routing them to Retell's SIP.express
: Handles server and request processing.twilio
: Manages Twilio's Voice API requests.retell-sdk
: Manages Retell's API calls for call registration and SIP routing.
For security, store your API key and Agent ID in environment variables:
RETELL_API_KEY=your_retell_api_key
RETELL_AGENT_ID=your_agent_id
PORT=3000
- Inbound Call: An inbound call triggers Twilio to hit the
/voice-webhook
endpoint. - Call Registration: The server registers the call with Retell and retrieves a
call_id
. - SIP Forwarding: The call is forwarded to Retell's SIP endpoint using the
call_id
.
Any errors during the call processing are logged to the console and a 500 Internal Server Error
is returned to the caller.
This project is licensed under the MIT License.
This integration setup was inspired by a solution provided by @Emagine Reality. For more insights and support, check out the AI Connect Skool group.
Ensure your Twilio phone number is correctly configured to forward calls to your server's /voice-webhook
endpoint. Additionally, check that Retell SDK credentials and Agent ID are properly set up.