Twilio Outgoing call from iOS - ios

Situation
I use Twilio iOS SDK for my iOS Voip application.
I'm trying to call from my Voip application to any numbers I stacked in some points though.
I already confirmed that Http request is sent to my app request url which I set on the url both when I make outgoing call from my Voip application and when get incoming call to my Voip application.
In short, below is the flow which I think it true when I call from my Voip application
type the number and call (iOS Voip Application ) -> the request url is called and returns TwiML to call number I typed(my server side) -> call to the number(Twilio Service) -> get call(phone)
Question
What is the best practice to call from Voip to any numbers?
can I set different request url for incoming and outgoing call separately in one application on the Twilio console, or we have a way to judge if it's incoming or outgoing call by parameter?
What kind of TwiML I should return when I want to make an outgoing call from my Voip Application to the phone?
My server side script returns <Response><Dial><Number>090xxxxxxxxx</Number></Dial></Response> when the request url which I set was called to call from my Voip application, but it failed unfortunately and recorded not as outgoing call but as incoming call on Twilio call logs. I know I should return <Response><Dial><Client>name</Client></Dial></Response> when it comes to get an incoming call I think it's not appropriate for outgoing one though.
Kind Regards.
Edit
Below is the request I got for incoming call from any phone numbers to my Twilio number and the TwiML I return to call my Twilio number in Voip application. It's working well.
[request]
<QueryDict: {u'FromZip': [u''], u'From': [u'+8190xxxxxxxx'], u'FromCity': [u''], u'ApiVersion': [u'2010-04-01'], u'ApplicationSid': [u'AP192f34d8a08f17592163af2c6cxxxxxx'], u'To': [u'+8150xxxxxxxx'], u'ForwardedFrom': [u'050xxxxxxxx'], u'CallStatus': [u'ringing'], u'CalledState': [u''], u'FromState': [u''], u'Direction': [u'inbound'], u'ToCity': [u''], u'ToZip': [u''], u'CallerCity': [u''], u'FromCountry': [u'JP'], u'CalledCity': [u''], u'CalledCountry': [u'JP'], u'Caller': [u'+8190xxxxxxxx'], u'CallerZip': [u''], u'AccountSid': [u'AC41ebdf749095141bfdb182fbd8fxxxxx'], u'CalledVia': [u'050xxxxxxxx'], u'Called': [u'+8150xxxxxxxx'], u'CallerCountry': [u'JP'], u'CalledZip': [u''], u'CallSid': [u'CA7afa3aae965d9207b7e8b065e9dxxxxx'], u'CallerState': [u''], u'ToCountry': [u'JP'], u'ToState': [u'']}>
[TwiML]
<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Client>name</Client></Dial></Response>
While the incoming call does work well, below is the debugged outgoing call request from my Voip application to any phone numbers via my server and the TwiML I returned. It has failed to call and I confirmed the Twilio call log shows no 'To' number while 'From' number is my client name which I used for capability.allow_client_incoming(my client name).
[request]
[TwiML]
<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number>090xxxxxxxx</Number></Dial></Response>

Twilio developer evangelist here.
If I were you, I would go through the Twilio Client quick start for iOS which will show you various ways you can build this.
To answer your questions.
You can't set different request URLs for inbound and outbound using the same number with Twilio Client, but you can tell whether it is inbound or outbound by checking the direction parameter.
You should use <Dial> and <Number> when going outbound VOIP to numbers. I don't know why that would fail. Could you possibly share more information on the error?

Related

Twilio: How can the SHAKEN/STIR status of an incoming call be accessed by the Webhook?

Programmable Voice docs indicate that the SHAKEN/STIR status is passed to the webhook for incoming calls, but I don't see it in the POST data. I wouldn't expect it in Lookups since that's not real-time, and I don't see it there either.
My set up is: a Twilio phone number, configured for Voice & Fax to accept incoming voice calls and POST them to a Webhook on my own server.
Added Information:
I think the issue may be threefold:
incoming calls without SHAKEN/STIR data won't have the parameter;
very few calls have SHAKEN/STIR data (based on my call logs)
(not sure why... even legitimate calls from major U.S. carrier numbers don't have it)
SHAKEN/STIR support in forwarded calls is "coming later"
This blog covers the topic.
Building SHAKEN/STIR verification Into Your Voice CAPTCHA IVR
https://www.twilio.com/blog/shaken-stir-verification-voice-captcha-ivr

Handling of StatusCallBack when Dialing a Number with Extension

When we Dial a Number with <Dial> tag, we provide the <Number> to which the call should be sent to. We can call an extension using SendDigits. How do we track if the call to the extension has been answered or not answered? Since the number is routed through an exchange, will Twilio always handle only the response of the exchange?
Twilio provides the DialCallStatus on the initial answer of the call which is handled by the device managing the extensions.
There isn't eventing available by the device handling the extensions for Twilio to capture, so you are correct, Twilio will only handle the response of the exchange.

How to connect one Twilio application instance to another via SIP?

I have an application that uses Twilio Programmable Voice.
The app is basically a call center. There are several instances deployed, each one has its own Twilio phone number and a pool of available human operators who can answer incoming calls. When GSM call is received from the customer to instance's Twilio phone number, Twilio invokes a WebHook on our side, and then we simply find an available person from the pool and return a TwiML like this:
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Say>Hello. Connecting you to the available operator.</Say>
<Dial callerId="{callCenterNumber}">{operatorNumber}</Dial>
</Response>
Now the customer is connected to available person from the application instance's pool. So far, so good.
Now I want to handle the case when no available operators were found in the pool of the application instance that was originally called. In that case, I want the original app instance to connect to another instance's Twilio phone number and to be treated as a customer of that instance, so that the original human customer will be connected to an operator from another instance's pool. To achieve this, instance A simply returns <Dial callerId="{callCenterNumber}">{anotherCallCenterNumber}</Dial> (dialing anotherCallCenterNumber instead of operatorNumber in the example above).
So, instead of this connection: Customer => Call Center A => Operator from A's pool, I have Customer => Call Center A => Call Center B => Operator from B's pool connection.
It also works fine and I can chain even more call center instances until available operator is found somewhere.
The problem is, I want to use SIP protocol for instance-to-instance communication instead of GSM phone numbers, because I need to pass some extra data (language, etc) along the way, so that the next instance knows how to handle the call and find the right operator to answer it. SIP headers looks like a suitable solution for passing this data. Everything else will stay the same.
So, I configured a SIP endpoint for each application instance and set up Request WebHook URLs in a similar manner to regular Phone Number WebHook URLs. Now, to dial another call center instance via SIP, I return the following TwiML:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello. No available operators were found. Connecting you to Call Center B.</Say>
<Dial>
<Sip>sip:callcenter#instanceB.sip.us1.twilio.com?x-customHeader=customData</Sip>
</Dial>
</Response>
At this point, I expect that Twilio will invoke instanceB SIP Domain's WebHook, so I can handle the call and route it the same way as I used in regular Phone Number WebHooks.
Instead of that, the call is dropped immediately, and in the Twilio Debugger I see following warning:
32009 - The user you tried to dial is not registered with the corresponding SIP Domain
After some research, I realized that callcenter endpoint must be registered in instanceB.sip.us1.twilio.com SIP domain. But, it seems like the only way to do that is using a softphone client app like X-Lite or Jitsi. I installed X-Lite locally and added a callcenter account. Now when Call Center A receives a call and instructs Twilio to dial Call Center B (sip:callcenter#instanceB.sip.us1.twilio.com), my local softphone starts ringing, and if I answer it, I will be connected to a customer calling Call Center A. This is not what I want at all!
Also, I found that if I call any address from the softphone, even unregistered one like sip:unknown#instanceB.sip.us1.twilio.com, then strangely enough Twilio will invoke instanceB SIP Domain's WebHook without any complains. But that's also not what I need. I need Twilio => Twilio connection over SIP in the same way as it worked when using Phone Numbers.
So, to sum up:
Is the described scenario with Twilio-to-Twilio over SIP communication possible at all, same way as Twilio-to-Twilio over Phone Numbers?
Why Twilio returns an error The user you tried to dial is not registered with the corresponding SIP Domain when it receives a TwiML instructing it to dial unregistered SIP endpoint, but at the same time it doesn't return that error when I'm dialing the same unregistered endpoint from the softphone client?
Unfortunately you cannot do this via SIP. Twilio doesn't host SIP endpoints for you.

Twilio Client - Sometimes no receiving disconnect from the caller

We're using twilio client (1.4) to place/receive calls and we have noticed that sometimes when the caller hangs up the call, twilio client doesn't receive the disconnect signaling and therefore, it keeps like it has a ongoing call.
Could we somehow avoid or minimize this behavior?
Regards,
Carlos
You can check call status issue in twilio website www.twilio.com with your credentitals. Go to calllogs and find the particular call(with SID- this Sid you can get it from twilio.device.incoming method ) and check the call status http response.(Most probably your statuscallback has some issue)

Twilio Hangup up immediately with no busy signal

For my Twilio number I have TwiML App and I am using Flask as a backend to handle URL for incoming calls. My goal is to create behavior that for every incoming call it hangs up (and send sms, but this is not so relevant at the moment)
so far I used:
Twiml Response with Hangup ends with "busy signal"
Twiml Response with Reject ends with message "number you are calling is not available"
using twilio rest client (like in Twilio's example) client.calls.update("CAe1644a7eed5088b159577c5802d8be38", status="completed") also results in "busy signal"
twilio rest client: client.calls.hangup(twilio_call_sid) also results in "busy signal"
so I am running out of ideas and I can't believe that it's not possible to finished incoming call (without answering) clearly with no busy signal, or I am probably missing something.
I would appreciate any help
Realize this is coming way late, but if you want to simply respond to incoming calls with an SMS you can use the <Sms> TwiML verb to do so.
And then from the users perspective, gracefully end the call with <Hangup>.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Sms from="+14105551234" to="+14105556789" action="URL_TO-HANGUP_TWIML">Say hello StackOverflow.</Sms>
</Response>

Resources