Sedrick
04/07/2025, 5:03 PM{
"message": [
"CallStatus must be one of the following values: ringing",
"Direction must be one of the following values: inbound, outbound"
],
"error": "Bad Request",
"statusCode": 400
}
Any guidance or clarification would be greatly appreciated.Vapi Support Bot
04/07/2025, 5:05 PMts
app.post('/twilio/voice', async (req, res) => {
// Create a Vapi call with bypass enabled
const vapiCall = await fetch('https://api.vapi.ai/call', {
method: 'POST',
body: JSON.stringify({
phoneCallProviderBypassEnabled: true,
// other call parameters...
})
});
const { callId } = await vapiCall.json();
// Return TwiML to connect Twilio to your websocket
const twiml = new VoiceResponse();
const connect = twiml.connect();
connect.stream({
url: `wss://your-server.com/twilio-bridge/${callId}`
});
res.type('text/xml');
res.send(twiml.toString());
});
This approach is documented in [Discord discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341810370700120064).
### 3. Use the Vapi API Directly
You can bypass the TwiML redirect by making a direct API call to Vapi:
```json
{Vapi Support Bot
04/07/2025, 5:05 PM### 4. Set Up Your Own Webhook Endpoint
Instead of auto-registering your Twilio number with Vapi, you can set up your own webhook endpoint, process the call as needed, and forward it to Vapi when required:
```python
@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"]
This approach is documented in [Discord discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1343397177182912553).
### 5. SIP REFER for Call Transfers
For more advanced scenarios, you can use SIP REFER to transfer calls with additional context:
```javascript
const transferDestination = {
type: 'sip',
sipUri: 'sip:genesys@your-domain.com',
transferPlan: {
mode: 'blind-transfer-add-summary-to-sip-header',
summaryPlan: {
// Configure how the summary should be generated
}
},
sipHeaders: {
'X-Caller-Intent': 'policy_inquiry',
'X-Caller-Details': JSON.stringify({
name: customer.name,Vapi Support Bot
04/07/2025, 5:05 PMKings_big💫
04/07/2025, 9:10 PMShubham Bajaj
04/07/2025, 10:39 PMSedrick
04/08/2025, 1:53 PMShubham Bajaj
04/10/2025, 9:49 PM