2

I have twilio.js setup in my rails application and works well, now what I need is after the call is disconnected I want to know the call status, if the call is not attended I have to call another number this is my disconnect function, how to check the call status using twilio.js?

Twilio.Device.disconnect(function(connection) {
  // Disable the hangup button and enable the call buttons
  hangUpButton.prop("disabled", true);
  callCustomerButtons.prop("disabled", false);
  callSupportButton.prop("disabled", false);
  updateCallStatus("Ready");
});

1 Answers1

0

Twilio developer evangelist here.

The connection object you receive should come with all the normal Twilio voice parameters. So, you can call on the parameters property to get those parameters and then look for CallStatus to tell you how the call finished.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • So After the call disconnected, I have to make AJAX request to get call status yes? – Navin Kumar Apr 11 '16 at 07:13
  • No, the callback you provide to the disconnect method will receive the `connection` as an argument and the parameters property on that will contain all the same parameters as if your server had received a webhook. So, you can look at `connection.parameters.CallStatus` and it will tell you how the call ended. You can, if you need to, also look up the status by calling the REST API with the call SID. – philnash Apr 11 '16 at 15:20
  • Unfortunately there’s not a way to use Twilio Client’s Javascript API to relay the status of the second call back to the browser. To achieve this, you would need to use some other communication mechanism. For example, you can make an AJAX or WebSocket request to your server from the browser to check if and have been requested. This way your server can pass that information in response to the AJAX request. This is the reply I got from twilio so I made one ajax call and getting call status – Navin Kumar Apr 12 '16 at 04:58
  • Oh, ha, ok! Sorry about that, I was under the impression that the call parameters would work the same. Sorry for misinforming you. – philnash Apr 12 '16 at 17:27