Call Forwarding and Callee ID - twilio

I would like to forward call from mobile phone numbers to a single Twilio number (using regular carrier forwarding functionnality).
I would like to know if there is any way to get the original callee id from the incoming call on the Twilio number (i.e. the mobile number of the original recipient of the forwarded call).
Said differently, I would like to be able, when I receive the call on Twilio, to make the difference between calls forwarded from the number A and calls forwarded from number B.
If this is not possible like this, is there any other option ?

My recommendation would be to not forward the calls to Twilio and call the Twilio number directly. The ability to capture the original called number is carrier dependent and not reliable.
ForwardedFrom - https://www.twilio.com/docs/voice/twiml#request-parameters
You could also forward the call to Twilio via SIP (rather then over the Public Switched Telephone Network), and possibly pass an X-Header with the original Caller ID, but that is most likely not possible with your existing carrier.

Related

Specifying Twilio Incoming and Outgoing Callbacks using TwiML App

I have a number which I have configured to use a TwiML App. In the App itself, I have set the VoiceURL and StatusCallback on the Voice section.
The issue is, the callback is triggered when there is an incoming call to the Twilio-bought number.
However, if I place an outgoing call from the Twilio-bought number, the callback is not triggered.
Is this the expected behaviour, that the TwiML app callback is only triggered on incoming calls?
If this is not the intended behaviour, any pointers on what may be going wrong?
That is expected, that statusCallback URL handles only the incoming call leg.
If you are forwarding that call(which creates another call leg), you can use the parameter of the name name of the Number noun to capture events.
If you are using the REST API to make an outbound call, it has a statusCallback parameter as well.

Twilio - determine if a number is already in a call before initiating

I have a somewhat peculiar situation for which I can't find documentation: I have an application that will use the Twilio API to initiate a voice call from phone number X (my number) to another one. The problem is that number X could already be in the middle of another call, one that was not initiated with Twilio (so my application wouldn't know about it). Would Twilio detect this, and send an error, or try to initiate the call anyway? If the former, what would the error be? I have found the error code for "callee busy", but nothing similar to "caller busy".
Alternatively, is there an API call I could make before initiating the call to make sure number X is available and not in another call?
Twilio numbers can have multiple calls associated with them, so there would be no error id the Phone X was on an existing call (since phone numbers can be routed however you choose). You can set the outbound CallerID to be another Twilio number or a verified callerID (but if they call that verified callerID back, it wont go back to Twilio but the carrier/business owning that number).
Once the dialed party answers after making the outbound API call, you tell Twilio how to route the other piece (who to connect the answering party to) via the URL parameter hosting the Twilio Markup Language (TwiML).
There is an API call and example for, Read multiple Call resources and filter by call status and phone number (Code Example), you could query before making your outbound call (assuming you always map inbound calls to the same endpoint) or routing your inbound call (which probably makes more sense if you want to re-route to another destination who can answer the call).
The status of this call. Can be: queued, ringing, in-progress, canceled, completed, failed, busy or no-answer.

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.

Check status of a non-Twilio number when forwarding a Twilio number to multiple phones

not sure how much sense my title makes.
Is there a way to check the status of a non-Twilio number before Twilio forwards a call to this number?
Use case: we forward calls to a Twilio number to three different cell phones. We also send a notification with which number ended up taking the call to all the three phones, after the call is over.
Problem: very often, the voicemail of one of our three phones answers the forwarded call, which we want to prevent.
Question: is there a way to check whether a cell phone is currently available (no voicemail would answer!) before forwarding a call to that number?
I do not believe exactly what you are asking for is possible. However, let me suggest an alternative that may get the job done.
When a call comes in, place the caller in a queue.
Initiate a call to your three phone numbers.
Ask for the person(s) you called to press one and gather the response.
The first person to press one has the queued call forwarded to them.

How can I tell if an incoming call is from OpenVBX but still see the caller's Caller ID information?

I have a OpenVBX/Twilio setup where I use its dial applet to call particular people in my company. However, when viewing an incoming call on my phone, I have no way to know if the caller is calling via OpenVBX or not.
Is there a way to customize OpenVBX/Twilio so that when viewing the caller's Caller ID on my phone, I can see the Caller ID information and some indicator that the call came through Twilio?
Thanks.
Not sure if this is configurable in OpenVBX itself, or if you'd have to change some of the Dial applet code, but you could just use the CallerID (number) of a Twilio number, instead of using the CallerId of the incoming call.

Resources