2

I am implementing Twilio SDK in the app and I've managed to make web to web calls and also web to phone calls.

I can't seem to manage to figure out how the switch from web to phone should be made.

I initially call the Voice.call() with an identity user_39 but if the user has no internet connection, and does not receive the push notification sent by me, how should the switch from web to phone be made? Is it somehow done automatically by the Twilio SDK or should I listen for the error response to Voice.call() and based on some status decide to remake the call with the actual phone number of the user?

I haven't been able to find a clear documentation regarding this.

AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106

1 Answers1

1

Twilio developer evangelist here.

If the user you are trying to call is not online then the call to them will fail. You will need to listen for this using a Call.Listener and the onConnectFailure event. If you detect that the call failed to the app then you can handle the failure and restart the call to the user's phone number.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Shucks. I was hoping the SDK would do this automatically. Give it the user's app identity, and also the number and have it autonatically redirect. But ok, if that's how it's done then that's how I shall do it. Now it makes sense why I was unable to find a solution in the docs :) Being a Twilio evangelist, would you care looking at this as well please? https://stackoverflow.com/questions/51974158/twilio-how-to-open-activity-when-calling-web-to-phone?noredirect=1#comment90903858_51974158 – AndreiBogdan Aug 23 '18 at 04:22
  • At least let me know if it's possible. Again ... I was not able to find any documentation in that regard :( – AndreiBogdan Aug 23 '18 at 04:23
  • The SDK only concerns itself with one number/identity to make a call to at any one time, so it's up to you to customise the behaviour beyond that. I've left a comment on that other question. – philnash Aug 23 '18 at 04:23
  • hehe. Yeah, I've just noticed you were the one answering there as well. Sorry. Thank you kindly for your help! – AndreiBogdan Aug 23 '18 at 04:26
  • hmm, interestingly, it does not go into onConnectFailure if the identity is given and the user doesn't answer. It goes into onCallDisconnected, without a status or exception or anything I could handle.. well, shucks. – AndreiBogdan Aug 23 '18 at 04:32
  • Oh, another idea might be to handle this in your TwiML application. You can send parameters when calling `Voice.call` and those parameters are available in the request to your TwiML app. You could send both an identity and a number then handle the result of the calls via the [``](https://www.twilio.com/docs/api/twiml/dial). – philnash Aug 23 '18 at 04:35
  • Oh, that sounds interesting. "handle the result of the calls via " is that handled automatically by the server or do I need to handle it somehow myself ? I've read about but I didn't quite grasp the idea of it ... – AndreiBogdan Aug 23 '18 at 04:38
  • If you give the `` a URL in the `action` attribute then once the call completes it will send a request to that URL including a `DialCallStatus` parameter. That will tell you whether the call was completed successfully, cancelled, failed and [some other statuses](https://www.twilio.com/docs/voice/twiml/dial#dialcallstatus). So, if the first call fails, you could respond to the action URL with another `` to make the call to the number instead. – philnash Aug 23 '18 at 04:41
  • Thanks. You've been a tremendous help ! – AndreiBogdan Aug 23 '18 at 04:52
  • Any idea on why the STATUS CALLBACK URL returns something like this? https://pastebin.com/UEqCmg30 I don't have anything relevant here from which to know if the call failed, so that i can make it again. :( – AndreiBogdan Aug 23 '18 at 08:01
  • I just tried that, on the server. But ... can you redirect somehow the call to another user but don't disconnect the caller ? I'm currently using the update() method, but it won't redirect from the identity "user_39" to the phone number "+xxxxxxxxx". :( – AndreiBogdan Aug 23 '18 at 10:25
  • That status callback has the status as "completed" which is a successful call. But you really want the response to the `action` URL for the `` which will give you a `DialCallStatus` which will relate to the call you try to make with the ``. Then if that fails you will get a failed status and be able to return new TwiML with a new `` to the number. – philnash Aug 24 '18 at 05:13