Lucio
03/13/2025, 6:53 PMVapi Support Bot
03/13/2025, 6:54 PMpython
from fastapi import FastAPI, Form
from starlette.responses import PlainTextResponse
import requests
app = FastAPI()
@app.post("/twilio/inbound_call", response_class=PlainTextResponse)
async def receive_call_data(
AccountSid: str = Form(...),
CallSid: str = Form(...),
To: str = Form(...),
From: str = Form(...)
):
# Authenticate the caller by checking your service
user_data = check_your_authentication_service(From)
# Forward to VAPI with environment variables
forward_to_vapi(From, user_data)
return "Call processed"
def forward_to_vapi(caller_number, user_data):
api_key = "YOUR_API_KEY"
r = requests.post("https://api.vapi.ai/call", json={
"phoneNumberId": "your-phone-number-id",
"phoneCallProviderBypassEnabled": True,
"customer": {
"number": caller_number
},
"assistantId": "your-assistant-id",
"assistantOverrides": {
"variableValues": {
"userName": user_data["name"],
"userType": user_data["type"],
# Add any other variables you need
}
}
}, headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
})
Vapi Support Bot
03/13/2025, 6:54 PMassistantOverrides.variableValues
object to pass your authentication data as dynamic variables that can be used in your assistant's prompts like Hello, {{userName}}!
[(source)](https://docs.vapi.ai/assistants/dynamic-variables)
This approach gives you complete control over the authentication process before the VAPI assistant even starts the conversation! 👍
Sources:
- [Detailed Report on Custom Code Execution for Inbound Call Authentication with VAPI](https://docs.vapi.ai/assistants/dynamic-variables)
- [Setting Environment Variables in VAPI](https://docs.vapi.ai/assistants/dynamic-variables)
- [VAPI Assistant Hooks System](https://docs.vapi.ai/changelog/2025/2/17)Vapi Support Bot
03/13/2025, 6:56 PMHam
03/13/2025, 7:49 PMLucio
03/13/2025, 7:55 PMNir S (CEO/Founder @Cloudonix)
03/13/2025, 8:30 PMLucio
03/18/2025, 6:39 PM