Twilio twiml: Hold music during call transfer - twilio

Do Play verb with loop 0 value cause the music to play till the call is connected?
https://www.twilio.com/docs/api/twiml/play

Twilio developer evangelist here.
Effectively in this situation you are looking to put your user in a queue while you dial your agents. This is how you'd do it:
First up, when you receive the incoming call you can respond with <Enqueue> that directs a user into a queue. You can set a waitUrl attribute that allows you to define either a music file or TwiML that will play while the user waits for the call to be answered.
<Response>
<Enqueue waitUrl='/wait-music'>incoming</Enqueue>
</Response>
While your incoming caller is waiting, you can then start making calls to your agents using the REST API. Once an agent connects and accepts the whisper you would then join the calls by dialling the <Queue>.
<Response>
<Dial><Queue>incoming</Queue></Dial>
</Response>
With this method you'd need to maintain whether your user has been answered yet and manually handle whether to redirect their call from the queue to more TwiML to <Record> a voicemail.
There is a more robust way to set all this up. It still requires enqueueing in the first place, but you should take a look at TaskRouter. It's an automated call distribution service with configurable workflows. There's a bit more setup involved on the Twilio side, but TaskRouter will handle directing calls to your agents and allow you to define rules for how to handle a user who's been waiting too long. I recommend you check out the TaskRouter documentation and then take a look at the quickstart guide as an example.
Let me know if that helps at all.

Related

Handing incoming calls - broadcast to multiple agents

I have an application where I need to delay answering the incoming call while I ring multiple agents in parallel, and then connect the incoming call to one selected agent. Note that for this application it is not an option to answer the call and play a MP3 that mimics a phone ringing - the calling system is an automated system that recognizes when the call has been answered and immediately looks for an agent to respond.
If I want to forward to a single agent's phone, <Dial> + answerOnBridge works perfectly.
I have not been able to come up with a solution for ringing multiple agents in parallel. My issue is holding off the incoming call from being answered. I've tried:
Delay responding to incoming webhook while I locate an agent (Twilio times out)
Respond to the incoming webhook with short duration <Pause> only. Twilio re-sends the incoming webhook after the timeout (with a new CallSid which complicates things). This might work (I can bridge the call on a later retry once I locate an agent), but unfortunately some carriers seem to not handle this <Pause> only - I see Call Failed.
Respond to the incoming webhook with long duration <Pause> + <Hangup>. Then when an agent answers, redirect the incoming call with client.calls().update(). This fails with:
TwilioRestException: HTTP 400 error: Unable to update record: Call is not in-progress. Cannot redirect.
NOTE: the update() works if I respond in a way that answers the incoming call ... but that doesn't work for me.
Is there some other way to keep the incoming call ringing / truly not answered while I broadcast call a few agents, and then connect the incoming caller to one selected agent? Conceptually I'd like something that does a <Enqueue> + answerOnBridge, but I'm running out of ideas for how this can be done...
Twilio developer evangelist here.
Have you tried using multiple <Number>s within your original <Dial answerOnBridge="true">? That would dial each number until one is picked up, connecting the agent who answered and cancelling the other calls.
Something like:
<Response>
<Dial answerOnBridge="true">
<Number>FIRST_NUMBER</Number>
<Number>SECOND_NUMBER</Number>
</Dial>
</Response>
Let me know if that helps.

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 Conference statusCallbackEvent="start speaker" not functioning

My Twilio server has 3 pages
/listener
Sets up a <dial> and <Conference statusCallback="/gather" statusCallbackEvent="speaker start"> and appends caller to said conference. In the conference, the events request should be sent on any user speaking and conference starting (starting is just used for debugging in case it's something wrong with speaking alone, but the starting request won't be sent as well).
/gather
Uses gather to listen to speech with action='/parse'
/parse
Parses the message.
Right now, when I set the webhook to /gather, I could see 2 POST requests to /gather and /parse no problem. But when I set it to /listener, only 1 POST request per call would appear and no subsequent requests would be sent on conference start or people speaking. Can anyone possibly tell me any example of statusCallbackEvent working with gather or provide any workarounds?
Twilio developer evangelist here.
It looks to me like you are trying to use speech detection on the ongoing conference call via events?
If that is the case, then I'm afraid that is not what statusCallbacks in <Conference> do. statusCallback events during calls are asynchronous callbacks, your response to them will not affect the ongoing call. Responding to a statusCallback event with TwiML will have no effect.
Subsequently, it's not possible to simultaneously continue a <Conference> and use <Gather> on the participants.

Recording multiple user answers in Twilio call

I am building an Interactive Voice Assistant using Twilio. My goal is to record parts of the conversation, process the recorded audio and
This is the answer to the /voice webhook (the one will receive Twilio's call)
<Response>
<Play>./welcome</Play>
<Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording"></Record>
</Response>
Processing the audio and providing an answer may take a long time, so I added a Pause at the end of /processing:
<Response>
<Play>./ok</Play>
<Pause length="10"></Pause>
</Response>
This is the answer when finished with /getRecording
<Response>
<Play>./answer</Play>
<Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording "></Record>
</Response>
/welcome, /ok and /answer lead to corresponding audio files.
So I was able to execute all steps, I can check in my logs that /getRecording is actually executed to the end and the twiml sent back again, but the /answer after /getRecording is never executed by Twilio (and the call just ends).
Do you have any guidance for it? Does Twilio accept multiple recordings on the same call?
Note: For some reason, if instead of using the 'recordingStatusCallback' I use /getrecording as 'action' it does work... but then we wouldn't be sure the recording we are using is really generated, right?
Thank you for your help!
Twilio developer evangelist here.
Your /getRecording endpoint is called, however that is an asynchronous webhook in the context of the call. Returning TwiML to the recordingStatusCallback will not affect the current call.
Instead, you should use the REST API to modify the call by redirecting it to the next TwiML you want to execute based on the response to the recording file.
Hopefully the recording does take less than the 10 second pause that you are using, but you may want to add a loop into your /processing endpoint so that the call won't hang up on your caller. You can do this by redirecting the caller back to the start again:
<Response>
<Play>./ok</Play>
<Pause length="10"></Pause>
<Redirect>./processing</Redirect>
</Response>
Then, when you get the recording callback you redirect your caller out of this loop.
Let me know if that helps at all.

Twillio Call Screening - Dial stops ringing

I am using twilio's call screening / whisper example. So basically when we use the Dial verb to call the number, we want to play a message when the receiver picks up the phone and give them the option to accept/reject the call. While the caller should keep hearing the ringing tone until the receiver makes a choice.
Most of this works as expected if we follow what's described in the call screening example https://www.twilio.com/docs/howto/callscreening
The problem is as soon as the receiver picks the phone, the caller can no longer hear the ringing tone, and the call goes silence until we have a response back from the receiver. This is a huge problem, because the caller will probably hang up once the ringing tone stops and there is no answer.
I have already had a look at the following two answers.
Twillio Call Screening silence on answer
Detecting when call had been answered using Dial verb
I personally don't want to go down the conference route.
In Number verb's documentation its clearly mentioned that the caller will continue to hear ringing tone.
https://www.twilio.com/docs/api/twiml/number#attributes-url
The 'url' attribute allows you to specify a url for a TwiML document that will run on the called party's end, after she answers, but before the parties are connected. You can use this TwiML to privately play or say information to the called party, or provide a chance to decline the phone call using Gather and Hangup. The current caller will continue to hear ringing while the TwiML document executes on the other end. TwiML documents executed in this manner are not allowed to contain the Dial verb.
The same issue happens with the Find Me Twimlet as well.
twilio.com/labs/twimlets/findme
Contacted Twilio support, you'll need to set "ringTone" attribute on like this:
<Dial answerOnBridge="true" ringTone="us">
I have tried that and it worked for me.

Resources