Please excuse our look. We're just getting started here.

Want to learn more about Twilio Forums? Check out our FAQ page here.

How can I get the "answered" call status for an outbound call from twilio using vanilla javascript

How can I get the "answered" call status for an outbound call from twilio using vanilla javascript

Answers

  • shelbyz
    shelbyz ✭✭✭

    Depending on how the call is created you should be able to provide a statusCallback and statusCallbackEvent filter to get a notification for answered calls. The code might look like (StatusCallback example):

    // borrowing from Twilio docs
    
    const accountSid = process.env.TWILIO_ACCOUNT_SID;
    const authToken = process.env.TWILIO_AUTH_TOKEN;
    const client = require('twilio')(accountSid, authToken);
    
    client.calls
          .create({
             method: 'GET',
             statusCallback: 'https://www.myapp.com/events',
             statusCallbackEvent: ['answered'],
             url: 'http://demo.twilio.com/docs/voice.xml',
             to: '+14155551212',
             from: '+18668675310'
           })
          .then(call => console.log(call.sid));
    

    When a call reaches an answered state Twilio will call the webhook provided as the statusCallback.

  • Hello shelbyz,

    Thanks for reply.
    I have referred below link to do voice call using quickstart.js and core PHP. As per your answer, i think its done using SDK. but in my case i am not using SDK.

    could you please help me to identify voice call status.

    In ongoing call, how can i get the call status is ringing.
    when user answerd the call how can i get the call status is answerd
    when user hangup the call (after answered) how can i get the call status is completed and
    when user hangup the call (without answering) how can i get call status is incompleted etc..

    Referred Link:
    https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-php

If this is an emergency, please contact Twilio Support. This is not an official Support channel. https://support.twilio.com/
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support