Shri
Shri

Reputation: 751

Twilio sends call completed status for all calls

I was setting up Status Callbacks for calls in nodeJS. I've set the 'CALL STATUS CHANGES' in phone number configuration to do a POST request to my node. But twilio seems to be sending call status completed for all calls no matter is the answer was 'busy', 'unanswered' or 'completed'.

Here's my node code for displaying call status sent by Twilio:

app.post("/status", (req, res) => {
  res.sendStatus(200);
  console.log(req.body);
});

Output for a busy call:

{
   ApiVersion: '2010-04-01',
   Called: '',
   CallStatus: 'completed',
   Duration: '15',
   From: 'client:AbrasiveHannahLiberty',
   CallDuration: '15',
   Direction: 'inbound',
   Timestamp: 'Fri, 20 Mar 2020 05:43:09 +0000',
   AccountSid: 'ACxxxxxxxx',
   CallbackSource: 'call-progress-events',
   ApplicationSid: 'APxxxxxxxx',
   Caller: 'client:AbrasiveHannahLiberty',
   SequenceNumber: '0',
   To: '',
   CallSid: 'CAxxxxxxxx'
 }

Upvotes: 1

Views: 873

Answers (2)

Quoc Minh
Quoc Minh

Reputation: 1

I think you should check the statusCallback URL in $dial->number() have to be different from URL of statusCallback you have configured in TwiML App?

Example: if statusCallback URL you config in TwiML App is ..../status, then in the $dial->number() you have to set to ..../events (or anything URL you like) just like this:

$response = new VoiceResponse();
$dial = $response->dial('');
$dial->number('+12349013030',
    ['statusCallbackEvent' => 'initiated ringing answered completed',
    'statusCallback' => '..../events',
    'statusCallbackMethod' => 'POST']); 

Upvotes: 0

Alan
Alan

Reputation: 10791

Twilio client calls have two call legs. When the Twilio client places an outbound call, that is the parent leg. Twilio automatically answers that call leg, so the TwiML associated with your Voice Request URL can be accessed, all calls will result in completed calls.

Once the client call is placed, the TwiML Application you defined (and convey to your Twilio Client via the Access Token) has a Request URL which is used to obtain TwiML, so Twilio knows what to do with the call and for example, places an outbound call to the public switched telephone network (PSTN), the child leg.

It is the TwiML in that Request URL that should use a Dial verb with Number noun and the statusCallback URL to get the status you are looking for.

TwiML™ Voice: Number

Upvotes: 2

Related Questions