Albert
02/24/2025, 1:40 AMPraveen
02/24/2025, 4:47 AM// Your webhook endpoint
@app.post("/twilio/inbound_call", response_class=PlainTextResponse)
async def receive_call_data(
AccountSid: str = Form(...),
...,
ToZip: Optional[str] = Form(None)
):
call_data = CallData(
AccountSid=AccountSid,
....,
ToZip=ToZip
)
r = requests.post("https://api.vapi.ai/call", json={
"phoneNumberId": "your-phone-number-id",
"phoneCallProviderBypassEnabled": True,
"customer": {
"number": call_data.Caller
},
"assistantId": "your-assistant-id"
}, headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
})
result = r.json()
return result["phoneCallProviderDetails"]["twiml"]
\[source\]
Key points:
\- You don't need to register your Twilio number directly with Vapi
\- You can dynamically decide when to forward to Vapi
\- The call can be forwarded using either SIP or TwiML Stream
\- Make sure to generate and track your own call IDsPraveen
02/24/2025, 4:47 AMAlbert
02/24/2025, 5:24 AMPraveen
02/26/2025, 1:43 AM