Voice Agents JS Example (ElevenLabs Conversational AI)
Voice Agents JS Example - ElevenLabs Conversational AI
This example demonstrates a simple Voice Agents script that integrates ElevenLabs Conversational AI with Vodia's PBX system. Unlike other AI integrations, ElevenLabs uses native SIP REFER for call transfers, making the implementation extremely straightforward - requiring only 3 lines of JavaScript code.
The audio (RTP) is established through a standard SIP call to ElevenLabs, and call transfers are handled natively through SIP REFER messages, eliminating the need for webhooks or websocket connections.
Setup:
ElevenLabs Dashboard Setup:
- Create a Conversational AI Agent:
- Log into your ElevenLabs dashboard at https://elevenlabs.io
- Navigate to the "Conversational AI" section
- Create a new agent and configure:
- Agent name and voice selection
- System prompt/instructions for the agent's behavior. Configure the agent's prompt to understand transfer requests (e.g., "When a user asks for sales, transfer to extension 4001")
- Knowledge base (optional)
- First message (greeting)


Example System Prompt
You are a professional phone assistant for [COMPANY NAME]. Your role is to greet callers and transfer them to the appropriate department.
Available Departments
Sales: extension 500
Marketing: extension 501
Support: extension 503
Operator: extension 700
Call Handling Instructions
Greet the caller briefly and professionally
When a caller requests a department, confirm and transfer immediately
Use the transfer tool with the appropriate extension number
After initiating transfer, end the call
If the caller requests a department that doesn't exist OR if you cannot understand their request, transfer them to the Operator (extension 700)
Response Style
Be brief and professional
Avoid unnecessary small talk
Confirm the transfer clearly before executing it
Example Interactions
Caller: "I need to speak with sales" You: "Transferring you to sales now." [Transfer to extension 500] [End call]
Caller: "Can you connect me to billing?" You: "I'll transfer you to our operator who can help with that." [Transfer to extension 700] [End call]
Caller: "Support please" You: "Connecting you to support." [Transfer to extension 503] [End call]
Caller: "Um... I need... uh..." You: "I'll connect you to our operator who can assist you." [Transfer to extension 700] [End call]
Caller: "I want to talk to accounting" You: "I'll transfer you to our operator who can direct you." [Transfer to extension 700] [End call]
- Configure Call Transfer and Call End Function:
- In your agent settings, add the system tool called
Transfer to number - Define a call transfer function with parameters:
- Description: leave blank
- Human Transfer rules
- Select
SIP REFERtransfer type. - Set Destination type to
SIP URI - SIP URI for eg could be
sip:500@sbc.vodia-teams.com - set Condition to
salesfor eg.
- Select
- You could also enable the
End conversationtool to end the call once transfered.
- In your agent settings, add the system tool called


- Enable SIP Integration:
- In your Agents platform, deploy a phone number or multiple phone numbers, each would connect to an Elevenlabs AI agent.
- The phone number could be any number for eg
45678or5001. - Assign the number to the elevenlabs agent.


