how to handle call transfer with twilio? - twilio

I'am using twilio to set up a call between 2 people
I'd like to manage call transfer asked from one side (like when a dtmf key is pressed). The other side could listen to a prompt who could be "please wait while your call is being transfered"
Any chance to do that properly with twilio?

When both parties are connected, Twilio blocks execution of further verbs until the caller or called party hangs up. That's why it is not possible in regular way.
But you can hangupOnStar attribute to hangup the caller party. And set an action URL to continue next dial verbs.
Here is a detail answer:
Twilio call transfer from in-call

Related

Setting statusCallbackEvent on outbound calls with Voice SDK

Is there any way to change what events trigger the status callback? Normally you can use statusCallbackEvent but I can't seem to find a way to make this work for the Voice SDK's leg of the call. It works fine on the call leg of the outbound participant, but not the Voice SDK's call leg. I only get completed status event for this leg (and I also can get ringing from the called action url).
Things I tried without success:
Updating the call using the REST api to set statusCallbackEvent to initiated ringing answered completed when the outbound call starts
Setting statusCallbackEvent as an outbound parameter on the Voice SDK's token (in PHP you can set custom parameters using $clientToken->allowClientOutgoing(...) but it seems normal parameters cannot be modified)
I really wish you could set this on the TwiML Application so that any numbers calling out with that application set will just automatically use your set events. That or let me set the parameters on the client's token.
One way to fix this is just to poll for the information but that is an ugly hack and isn't real time.
Twilio developer evangelist here.
I don't think you can do what you're asking for here, but for good reason.
When you are placing the call from the Voice SDK, that call leg is then between the application and Twilio. You know the call was "initiated", because you started it. There is no "ringing" because Twilio is not a phone and won't ring. You know it is "answered" because a request is made to your voice URL defined by the TwiML app. And finally, you do get the "completed" event.
As you say, you do get the events for the outbound leg of the call from Twilio to another phone number.

Twilio: Dial failover on busy signal

Scenario:
Person A calls my server. My server returns Twiml with Dial plus extra, connecting them to my client C. Sometimes C's phone is busy, and the extra just tells A they couldn't be connected, try texting.
I want to have a failover, where the same thing happens when C is not busy, but if C is busy, A is put in a queue, as are subsequent callers. When C's call ends, I try to connect A to C.
Is there a way of doing this with simple Twiml verbs, like dial.queue, and Redirect? So far I've failed: I can enqueue A when C is busy, hearing hold music and all, but I've utterly failed to get A off the queue and in touch with C. I suspect I'll need to create calls using the API, but figured I'd ask to see if the Twiml way should be doable.
I am aware that I could just throw all callers into a queue, but for business reasons I want to preserve the "ring and connect" behavior when the client is immediately available.
Twilio developer evangelist here.
The bit here is getting A to start a new call once they are done with the call they are on. You could, for example, send an SMS message to A to tell them that someone is waiting in the queue. Then, when they call their Twilio number back return TwiML that <Dial>s into the <Queue>.
When using the <Queue> TwiML, the caller will be connected to the person waiting at the front of the queue.
Alternatively, if you don't trust A to call the queue back, you could keep trying to periodically make calls to A using the REST API and once the call connects return the same TwiML to <Dial> into the <Queue>. If the caller hangs up and the queue becomes empty before A answers the call, you can stop calling and perhaps send a message to inform A that someone called and they can choose to call them back.

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.

Twilio call forwarding from caller to third party number

I want to ask if it's possible to forward call not from called side but from caller? For example, first user calls to second user. Second user picks up. Then system (or second user) automatically (or on button click somewhere) calls to third user and the first user hangs up the call so when third user picks up then there are second user and third user on the call?
Thanks.
I was able to forward call from called user to thid party but the common user was caller. For example it's described here - https://www.twilio.com/docs/voice/tutorials/call-forwarding-nodejs-express but it's not what I need. I want to forward call from caller not from called user.
Twilio developer evangelist here.
This seems like something you could achieve using a <Conference>. You could have the first user dial a Twilio number that dropped them into a conference call with the following TwiML
<Response>
<Dial hangupOnStar="true" action="/dial-next-user">
<Conference>Forwarder</Conference>
</Dial>
</Response>
This would set the initial caller to listen to hold music. You could then initiate an outbound call with the REST API to caller 2 by creating a participant for the conference. This will dial the user into the conference too.
Now, to get caller 1 to hangup and connect to caller 3. Notice I included hangupOnStar="true" to the <Dial>. This would allow caller 1 to press * and leave the call. When they do that Twilio will make a webhook to the URL defined by the action attribute. You can then respond to that request by dialling in caller 3 using the same participants API and thus achieving connecting caller 1 to 2 and then 2 to 3.
Let me know if that helps at all.

Twilio Child Call Status incorrect?

I'm experimenting with Twilio and I'm confused a bit by the ultimate status of my calls.
Here's what I'm doing. I'm making a call to a Twilio Phone Number which is hooked into an application endpoint. The app makes a database record of the call and then uses Twiml to make a secondary call out to another phone. After the call is complete, the call record is updated with data retrieved from Twilio then a secondary call record is created from the call in my account where its parent_call_sid is my original call's sid.
My issue is, if I call the Twilio Number but let the Twiml Dial timeout, the child call status ends up being 'completed' instead of 'no-answer'.
My question is why is this happening? Do I need to configure how I dial out differently in order to receive the appropriate status for my calls?
UPDATE:
This has been resolved. The issue was voicemail picking up before Twilio's default timeout of 30 seconds ended the call, resulting in a 'completed' status. By reducing the timeout Twilio was able to end the call with 'no-answer' before the voice mail picked up.
The issue was the timeout was long enough for the voice mail to pick up, which does not count as no-answer. Reducing the Timeout so that Twilio ends the call before voice mail answers correctly results in a no-answer status.

Resources