Telephony

Handle Twilio Call

Handle inbound calls from Twilio via WebSocket Media Streams.

Flow:

  1. Parse Twilio webhook (To, From, CallSid)
  2. Lookup customer by To number -> sip_number
  3. Get customer's pipecat_agent_id and AgentToken
  4. Check agent availability via router API
  5. If no agent: return hold music TwiML with <Redirect> to re-check
  6. If agent available: return <Connect><Stream> TwiML
  7. Twilio opens WebSocket directly to bot -> bot speaks immediately

On hold music redirects (attempt > 1), steps 3-4 (call creation, CNAM, status callback) are skipped since they were already done on the first attempt.

post/telephony/call

Response

Successful Response

{"stackTrail":"paths:/telephony/call:post:responses:200:content:application/json:schema","oasType":"schema","type":"unknown"}

Changes