"CallStatus must be one of the following values: r...
# support
l
Hello, I am trying to pass an id when calling a VAPI phone number. I have figured I can use DTMF digits and call a Twilio phone number like that: "+14155161111,123" (where the id I want to pass to the assistant is
123
) I read that VAPI currently does not handle DTMF digits, so I figured I could use TWIML to handle that and reroute the call to VAPI. I have two Twilio endpoints now. The example code gathers three digits and redirects the call to VAPI:
/api/twilio/call
Copy code
import { NextResponse } from "next/server";
const VoiceResponse = require("twilio").twiml.VoiceResponse;

export async function POST(): Promise<Response> {
  const twiml = new VoiceResponse();

  twiml.gather({
    numDigits: 3,
    method: "POST",
    action: `${process.env.NEXT_PUBLIC_VAPI_SERVER_URL}/api/twilio/gather`,
  });

  twiml.redirect(
    {
      method: "POST",
    },
    "https://api.vapi.ai/twilio/inbound_call",
  );

  console.log("twiml", twiml.toString());

  return new NextResponse(twiml.toString(), {
    headers: {
      "Content-Type": "text/xml",
    },
  });
}
/api/twilio/gather
Copy code
import { NextResponse } from "next/server";
const VoiceResponse = require("twilio").twiml.VoiceResponse;

export async function POST(req: Request): Promise<Response> {
  const formData = await req.formData();

  console.log("Digits", formData.get("Digits"));

  const twiml = new VoiceResponse();

  twiml.redirect(
    {
      method: "POST",
    },
    "https://api.vapi.ai/twilio/inbound_call",
  );

  return new NextResponse(twiml.toString(), {
    headers: {
      "Content-Type": "text/xml",
    },
  });
}
*Problem*: after I gather digits, call status changes from
ringing
to
in-progress
. That leads to a
400
error from VAPI:
Copy code
{
  "message": [
    "CallStatus must be one of the following values: ringing"
  ],
  "error": "Bad Request",
  "statusCode": 400
}
How can I solve this issue. Any other solutions for passing the id to the app is helpful.
v
The reason for the 400 error you're seeing is that VAPI expects incoming calls to have a "ringing" status, but after gathering DTMF digits, Twilio changes the call status to "in-progress". This is standard Twilio behavior that can't be changed.
s
After gathering DTMF tones, you have to transfer the call to the Vapi assistant using conference call.
@Lukas Narus let me know if you require further help.