def twilio_inbound_call(request_body):
"""Receive Twilio incoming call webhook and forward it to Vapi."""
Caller = request_body.get("Caller", "")
CallSid = request_body.get("CallSid", "")
To = request_body.get("To", "")
From = request_body.get("From", "")
ai_assistant_number = AiAssistantNumberMapping.objects.filter(phone_number=To,
assistant__assistant_type=AssistantConstants.INBOUND_CALL_ASSISTANT).last()
ai_assistant_provider= AiProvider.objects.filter().order_by('-id').first()
# Prepare payload for Vapi
assistant_overrides = {
'current_time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
}
payload = {
"phoneCallProviderBypassEnabled": True,
"type": "inboundPhoneCall",
"assistantId": ai_assistant_number.ai_assistant_id,
"phoneNumber": {
"provider": "twilio",
"number": ai_assistant_number.phone_number
},
"customer": {
"number": From
},
"phoneNumberId":ai_assistant_number.phone_number_id,
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {ai_assistant_provider.auth_token}"
}
# Send request to Vapi
response = InternalRequestHandler.post("https://api.vapi.ai/call", json=payload, headers=headers)
return response
is this correct approach