Voice AI & Conversational AgentsTelephony and deployment · Lesson 6 of 17

Telephony: phone numbers, SIP trunks and Twilio

Article · 17 min · 9 min lecture

Video lecture

Telephony: phone numbers, SIP trunks and Twilio

13 chapters · about 9 min · full transcript

Coming soon

Chapter 1 of 13

Telephony for voice agents

  • Phone calls ≠ browser audio
  • Numbers, SIP, Twilio
  • Inbound, outbound, transfers
  • Voicemail and keypad tones

The narrated lecture is in production

Every chapter is scripted and ready. Browse the chapters and read the full transcript now — the video will appear here when it’s published.

Chapters

Why telephony is its own skill

A web voice widget talks over the internet with good audio. A phone call crosses the public switched telephone network (PSTN): narrowband audio (often 8 kHz), codecs, carrier routing, caller ID rules, regional regulations, and the expectation that it just works. Most business voice agents live on the phone, so understanding the plumbing saves you days of debugging.

Key concepts

TermMeaning
DID / phone numberA number people dial; bought from a carrier or CPaaS provider (for example Twilio, Vonage, Telnyx, Plivo)
CPaaSCommunications Platform as a Service: APIs for numbers, calls and messages
SIPSession Initiation Protocol: the signaling standard for internet telephony (setting up, transferring and ending calls)
SIP trunkA connection between your phone system or carrier and another SIP endpoint (for example your voice agent platform)
RTP / mediaThe actual audio stream, separate from signaling
CodecAudio encoding such as G.711 (mu-law/A-law, 8 kHz), common on phone networks
DTMFKeypad tones ("press 1")
Warm vs cold transferWarm: agent or system briefs the human first (or conferences in). Cold/blind: call passed directly
SIP REFERA SIP method to transfer a call to another destination

Three ways to connect an agent to phones

  1. Native platform integration. Platforms like ElevenAgents let you import a Twilio number (or buy/assign numbers) and route inbound calls to an agent, plus place outbound calls via API. Fastest path.
  2. SIP trunking. Point an existing phone system, contact center platform or carrier trunk at the agent platform's SIP endpoint. Best when you already have numbers and a PBX or contact center (for example keeping your UAE or Pakistan numbers with a local carrier). OpenAI's Realtime API and LiveKit also accept SIP.
  3. Media streaming via CPaaS. Twilio's Media Streams send raw call audio over WebSocket to your server, and Twilio's ConversationRelay handles STT and TTS for you and sends text over WebSocket to your LLM app. You write more code but control everything.

Inbound call flow (typical)

Caller dials +971 4 XXX XXXX
 -> Carrier -> CPaaS number (e.g. Twilio)
 -> Webhook or SIP routing -> Voice agent platform (agent_id)
 -> Agent greets with AI disclosure (and recording notice if recording)
 -> Tools (CRM lookup by caller ID, booking API)
 -> Resolve, or transfer to human (SIP REFER / conference) with context
 -> End call -> post-call webhook with transcript, evaluation, data fields

Outbound calls

Outbound use cases include appointment reminders, lead follow-up and payment reminders. Outbound carries the heaviest legal risk (consent, calling hours, do-not-call lists, AI disclosure, caller ID rules), covered in Module 5. Technically you:

  1. Load the contact and consent status from your CRM.
  2. Pass dynamic variables (name, appointment time, reason) at call start.
  3. Enable voicemail detection to leave a short message or hang up.
  4. Handle retries politely (limits per day, respect time zones).
  5. Log outcomes back to the CRM.

Many platforms also support batch calling for campaigns; add pacing and suppression lists.

Transfers that do not frustrate people

  • Tell the caller what is happening ("I'm connecting you to Sara at reception now").
  • Pass context: summary, caller details, reason. SIP headers or user-to-user information can carry IDs; many platforms send a summary to the human's screen or CRM.
  • Have a fallback when nobody answers: take a callback number, or offer a booking.
  • Respect business hours: outside hours, do not transfer to an empty line.

Audio quality on phone lines

  • Phone audio is narrowband: TTS voices that sound great on headphones can sound thin. Test on real phones.
  • Background noise: noise suppression helps ASR; ask callers to repeat politely, not repeatedly.
  • DTMF: let callers type account numbers on the keypad where speech recognition struggles (and the agent can send tones to navigate other IVRs).

Worked example: a Riyadh car-service center

Inbound: a Saudi number with a local carrier connects via SIP trunk to the voice agent platform. The agent answers in Arabic by default, detects English speakers, books service slots through the dealership management system API, and transfers to the service desk via SIP REFER during working hours with a summary. Outbound: day-before reminders to customers who opted in on their service contract; voicemail detection leaves a short Arabic message with a callback number. All calls carry the AI disclosure in the first sentence; data stays in regions compliant with KSA PDPL transfer rules (verify vendor processing locations).

Hands-on: place an outbound call through ElevenAgents with Twilio

import os
from elevenlabs.client import ElevenLabs

client = ElevenLabs(api_key=os.environ["ELEVENLABS_API_KEY"])

def remind(to_number: str, name: str, appt_time: str, consent_ok: bool):
    if not consent_ok:
        raise ValueError("No recorded consent for automated calls to this number")
    resp = client.conversational_ai.twilio.outbound_call(
        agent_id=os.environ["REMINDER_AGENT_ID"],
        agent_phone_number_id=os.environ["AGENT_PHONE_NUMBER_ID"],  # the imported Twilio number in ElevenAgents
        to_number=to_number,  # E.164 format, e.g. +9715XXXXXXXX
        conversation_initiation_client_data={
            "dynamic_variables": {"customer_name": name, "appointment_time": appt_time}
        },
    )
    return resp

Check the current SDK reference for parameter names; there is an equivalent SIP trunk outbound method. Wrap calls with consent checks, calling-hour checks for the recipient's time zone, and suppression-list lookups.

Pitfalls

  • Testing only on laptop speakers; phone audio behaves differently.
  • Cold transfers with no context, so callers repeat everything.
  • Outbound campaigns without consent records, calling-hours logic and suppression lists.

Key takeaways

  • Phone calls use narrowband audio over the PSTN; test voices, ASR and turn-taking on real phones.
  • Connect agents via native CPaaS integrations (e.g. Twilio import), SIP trunks from existing carriers or PBXs, or media streaming (Twilio Media Streams/ConversationRelay).
  • Inbound flows need disclosure, CRM lookup and warm transfers with context and fallbacks.
  • Outbound calls need consent checks, dynamic variables, voicemail detection, time-zone-aware retries and suppression lists.

Check your understanding

Quick questions to lock in the lesson. They don’t count towards your certificate.

  1. A clinic in the UAE wants to keep its existing local numbers with its current carrier and connect them to a voice agent. Which approach fits best?
  2. What makes a transfer to a human 'warm'?
  3. Before placing an automated outbound reminder call, what must your code check first?

Put it into practice

Connect a test number to your agent. Call it from a real mobile in a noisy room, try a transfer, and note any ASR or turn-taking issues. Implement the outbound call function with consent and calling-hours guards.

Enrol for free to save your progress

Reading is always free. Enrol to keep your place, take the final assessment and earn a verifiable certificate.