I want to set up a system where if a transferred call is not answered, it is moved back into a queue so that someone else can grab it. I have the basics of catching the Dial status and then redirecting no-answer calls back to the queue.
My struggle is with the callerId. For inbound calls, everything works great and the correct inbound callerId shows at every step in the process.
For outbound calls using the Twilio Client, I can only get half way.
Assume:
Business phone number = 555-555-5555
Customer phone number = 222-222-2222
Agent A dials outbound
Sid1: incoming clientAnonymous
Sid2: from: 555-555-5555 to: 222-222-2222
Agent A then transfers to Agent B
<Response>
<Dial callerId="+12222222222" action="/catchNoAnswer"><Client>AgentB</Client>
</Dial>
</Response>
Agent B correctly sees the callerId as the customer.
Sid3: from: +12222222222 to:AgentB
If AgentB doesn't answer, I want to put the call back into a queue, but no matter what I try, the queue always shows the "from" number as the business phone number rather than the customer phone number. With multiple agents, this results in several calls in the queue all showing the business phone number rather than the customer phone numbers that the calls really represent.
I don't want to use a conference to do a warm transfer.
Is there any way to set the callerId to the to number before enqueuing a call?
I have tried dialing a conference with the callerId set, similar to how I dialed the client, and then moving that leg of the call back to the queue, but the callerId didn't stick.
Related
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.
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.
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.
So here what i have, when a user A calls my Twilio number, the call is forwarded towards another user B number through a Twiml response which dials user B number. I have done a time limit for any calls which is 5 minutes, but i would like to prevent the two users when there is only 1 minute left that time is nearly up and avoid cutting out aggressively the call.
Any one has an idea how to do that ?
Twilio developer evangelist here.
You could have the users actually call into a <Conference> (generating a call to user B when user A calls and enters the conference) and then start a timer for 4 minutes on your server. When the timer is done you can then check if the conference is still live (by calling the REST API and checking the conference status) and if it is dial one more caller into the conference.
That caller could be a recorded message that you play with <Play> or a message to be read out with text to speech using <Say> that lets the callers know that there's only one minute left.
For example:
<Response>
<Say voice="alice">Warning. There is only one minute of calling time left.</Say>
<Hangup/>
</Response>
Update
This is now better done with announcements that can be played into conferences. Check out the blog post here with details on how to announce messages into a conference.
I'd love some advice on my twilio setup for a problem I'm trying to solve.
Overview:
Each user in our system is provisioned a twilio phone number that they can hand out to anyone to contact them.
If personA contacts a user in our system (userB) via the provisioned twilio phone number, we'd like to connect them with userB if they are available. If userB is not available, we'd like to direct personA to voicemail. In other words, we want to make sure that we have control of the voicemail experience and the voicemail itself so that we can store it in our system, rather than having the voicemail be left on userB's device.
Current solution:
PersonA's incoming call gets added to a queue. At the same time, the system dials out userB.
UserB is asked to press 1 to accept the call. The reason for the explicit entry from UserB is to detect whether UserB is available to answer the call. (For example, if the call to UserB goes to their personal voicemail, the explicit digit entry will not happen telling us they are not available to answer.)
If UserB does not enter 1 in a specified amount of time, PersonA is directed to voicemail.
If UserB presses 1, call to UserB is modified (via twilio rest api) to dial the queue that PersonA is in to connect UserB and PersonA.
Problem with current solution:
In this solution, the control of when to divert personA's call to voicemail is controlled by the outcome of the call to UserB, which seems suboptimal. For instance, we may not be able to call UserB at all. In this case, personA would stay in the queue indefinitely.
What I'd like to happen in this case is to poll the queue personA is in to check the time in queue, and divert the call to voicemail if time in queue is greater than a threshold. However, it does not seem like it is possible to accurately know how long a call is unattended in a queue because:
The status of a call in a queue is in-progress even if the caller is listening to wait music. This is the same status as if PersonA's call had been answered.
If UserB dials into the queue, the call is only dequeued when the bridged parties disconnect, with no change in the call status of PersonA's call to indicate that they have been connected to UserB.
Questions
Is my understanding of why I cannot poll the call queue to divert calls to voicemail correct?
Should I instead be calling PersonA into a conference, and if UserB is available, connecting him/her to the conference that PersonA is in?
If I use a conference setup, what would be the easiest way to detect how long PersonA has been waiting in the conference so as to divert PersonA's call to voicemail in the event of UserB never joining the conference?
Twilio developer evangelist here.
I think you may have overcomplicated things a bit here with the queue. You can actually provide the message and gather within the original call without having to dial out yourself and eventually connect the two calls.
Here's how:
Your incoming call TwiML should look like this:
<Response>
<Dial action="/call_complete" timeout="30">
<Number url="/whisper">
ONWARD DIAL NUMBER
</Number>
</Dial>
</Response>
Giving the <Number> noun a URL will play the TwiML contents of that URL before the two calls are connected. You can use <Gather> in here to make sure the user has answered the call and not their own voicemail system:
/whisper
<Response>
<Gather numDigits="1" timeout="10" action="/gather_result">
<Say voice="alice">You are receiving a call, press any key to accept</Say>
</Gather>
<Hangup/>
</Response>
The /gather_result needs to work out whether a key was pressed or not. If it was pressed then we head through to the call, which we can do with an empty response as this gives control back to the original <Dial>. If no number was pressed we hangup this end, which causes the original <Dial> to complete and direct onto its action attribute. (I'm not sure what language you're working with but here is some Rubyish pseudo code)
/gather_result
<Response>
if params["Digits"] and params["Digits"].empty?
<Hangup/>
end
</Response>
/call_complete will then get called once the <Dial> action is over. If the status of the call at this point is "completed" or "answered" then the user has picked up the call and responded correctly to the whisper and we can hang up. If it's anything else, we redirect our call onto our voicemail recorder.
/call_complete
<Response>
if params["DialCallStatus"] == "completed" or params["DialCallStatus"] == "answered"
<Hangup/>
else
<Say voice="alice">The call could not be answered this time, please leave a message</Say>
<Record action="/record_complete" />
end
</Response>
Then finally your /record_complete action can do whatever you want with the recording URL and hang up the call.
/record_complete
<Response>
<Hangup/>
</Response>
This can all be achieved with Twimlets, as described in this blog post. Let me know if this helps at all.