How to determine if TwiML Dial with Queue was successful? - ruby-on-rails

Setup
My Ruby on Rails app has an initial caller who is successfully enqueued. The music plays while Rails creates an outbound call to a called party. The called party is then successfully connected to the initial caller by dialing into the queue:
response = Twilio::TwiML::VoiceResponse.new
response.dial(action: process_dial_call_status_path) do |dial|
dial.queue()
end
render xml: response.to_s, status: :ok
The Twilio docs indicate that the action attribute will be used by Twilio make a request to my endpoint specified, but only "after the dialed call ends". I need to know the outcome of how Twilio handled my response. My fear is that the initial caller will be forever listening to queue music because the called party did not successfully Dial the Queue. The default queue music is quite nice though!
Question
How can I know if the Dial into the Queue was successful?
I know a Call can have a status of "in-progress" or "completed" (among others). Does a call-to-call queue have a similar concept in terms of statuses that the app can know about?
Addendum
When I intentionally attempt Dial to Queue by the wrong queue name, the called party line errors ("an application error has occurred") and hangs up. I receive back a parameter that is not in the documentation. The only place I can find a reference to it is https://github.com/BTBurke/twiml/blob/master/callbacks.go#L33
"DequeueResult" => "queue-not-found"
Should I expect this response to be documented?

Twilio developer evangelist here.
This is an interesting question, not one I've come across before. Initially, I thought that the initial <Enqueue> element might be able to help out. <Enqueue> has an action attribute which is a URL that receives a webhook "when the call leaves the queue, describing the dequeue reason and details about the time spent in the queue". However, "in the case where a call is dequeued via the verb, the action URL is hit once when the bridged parties disconnect." So that doesn't tell us about the result of the dequeue until too late.
One other thing that <Enqueue> gives us is the waitUrl. While the default hold music is, ahem, great, providing your own response here can be a better idea because of the information the waitUrl receives each time Twilio comes to the end of the verbs and makes another request to the URL. The request parameters give you information like the current queue position of the call, how long the call has been in the queue, as well as the total queue size and average time calls spend in the queue. This doesn't tell you anything about the success of a <Dial><Queue> though, it's just interesting data to understand.
I think the best bet here is the url attribute on the <Queue>. This is usually used to perform a whisper to the person in the queue to let them know that they are now being moved out of the queue (a nice thing to implement anyway!). When a call is dequeued from the queue with a <Queue> that has a url the URL in the attribute will receive a request. You don't need to return TwiML to this request, an empty response will just bridge the calls, but the request will let you know that the call to the queue was successful.
It won't tell you whether the call was unsuccessful though. And that's where you can use the <Dial> element's action URL. That action URL will receive a request when the dialled call fails.
So, between the <Queue> element's url attribute and the <Dial> element's action attribute you can know whether your call to the queue was placed successfully or failed.
Regarding the "DequeueResult", that's not something I've seen before and we are looking into it internally.

Related

Handling 3 call queues in twilio in an elegant way

I'd love some advice on my twilio setup for a problem I'm trying to solve.
Overview
A client can call our twilio number and have one of three cases to handle:
- is our client and has a question - should be transfered to CC queue (2ppl),
- wants to buy our services - should be transfered to Sales queue (7ppl),
- has some other case - should be transfered to a different queue, lets call it Other (1 person)
Current solution
The client calls:
welcome message
we gather his digit input
enqueue a call to the appropiate queue
assign a task to an available worker with the conference instruction
Problem with the current solution
If there are no workers in the office to handle the call the client will wait forever until he hangs-up by himself. The wroker who answers doesn't know the clients phone number so he isn't able to fallow-up if neccesary.
Questions
After the client picks a queue i would like to check if I have any workers in the office in that queque (not in Offline mode). If everybody is on offline mode redirect to voicemail and a an email is sent to a specified email address with the caller phone number and voicemail recording url.
After the worker picks-up (accepts the reservation) send him a message with the clients phone number.
If no worker answers within a specified amount of time (for example 5 minutes) the call gets redirected to voicemail and a an email is sent to a specified email address with the caller phone number and voicemail recording url.
Twilio developer evangelist here.
Answers in order, parts 1 and 3 need to talk about voicemail which I'll cover at the bottom:
You can use a skip_if expression to skip a queue if there are no available workers.
I assume this is using the reservation.conference instruction in the JavaScript SDK. You can actually inspect the reservation object at this stage too, check out reservation.task.attributes for all the task attributes, which should include the call attributes. You can use this to show your agent on screen or send them a message some other way.
For this, you should set a timeout on your queue. When the timeout fires the task should drop through to the next queue in the workflow.
Voicemail
For parts 1 and 3 we are ejecting a task from one queue, but it needs to go somewhere else to be dealt with. You want to send the calls to voicemail, which doesn't require an agent to deal with it. Currently, the best way to deal with this is direct the task to a queue that has one bot worker in it. The job of the worker is to redirect incoming reservations straight to some TwiML. You achieve this by instantly responding to an assignment callback with the redirect instruction.
To create voicemail, you can combine <Say> and <Record>. Make sure you set the recordingStatusCallback attribute to a URL in your application, you can then use the results to email the link to the voicemail recording.
Let me know if this helps at all.
thank you for yout time to answer my questions. Below please find my reply:
1. It seems that this does not work in console - I find this information in the documentation "skip_if cannot be configured through the console - it must be posted on the workflow API". As I am not using the workflow API this is probably not a solution for me.
2. I using this tutorial: https://www.twilio.com/docs/quickstart/php/taskrouter/twiml-dequeue-call but instead of using dequeue instruction i use conference. I don't quit get how to "inspect the reservation" - maybe you have a tutorial on that? While looking for other solutions I came up with workspace event calback, but I am not sure if this would work.
3) How can I do that in the console?

Redirecting a twilio task to a new TwiML after task/reservation timeout

Currently using Twilio TaskRouter to build a telephony call center to route the calls.
My target was:
When a task kept pending for a certain time(i.e: no workers are available for reservation), redirect it to voicemail
When a task is reserved but the the worker didn't response to it, redirect it to voicemail
My Current Implementation was:
Specify both task timeout and reservation timeout
When task timeout / reservation timeout callback is triggered, query the Redirect Instruction reservation api to redirect it to a TwiML of recording voicemail.
But the problem was:
When a task is in pending status, no reservation was created so that I could not access the reservation to perform a redirect
When a reservation is timed out, trying to perform a redirect would receive an execption from Twilio saying that the reservation was nolonger available for redirecting
Twilio developer evangelist here.
There's two issues here, as you've said at the end. You're either trying to move a reservation that doesn't exist or redirecting a reservation that isn't available to redirect.
I think you can achieve your goals by using the workflow instead.
First up, consider the task side of things. You give a task a timeout. When it does timeout the normal behaviour for a task is to move to the next queue that it matches in the workflow.
I'd suggest setting up a final queue that has one permanently available worker object (but not real person) in it. When you get an assignment callback for a reservation for a task in that queue then you can use the redirect assignment to send the call to some TwiML that returns a <Record> to take a message. Your TwiML application can also call the REST API to accept the reservation.
That works for tasks that are never assigned from the initial queue to a worker. For the reservation timeout side of things, consider this.
When a reservation times out, the task goes back into its original queue for assignment again. The task remains under the same original timeout that we defined for it above, so will eventually move to our voicemail queue when the task itself times out. This has the same effect for the caller, as they never know when a reservation is assigned as they'll just be experiencing the wait music in the queue they are in.
Does that make sense at all?

How to connect 2 anonymous inbound callers with Twilio

I have read a couple similar posts here on SO, however the responses do not explaiin how, they only explain that it is possible with Twilio. If a Twilio Evangelist could give me some specific direction on this it would be greatly appreciated.
The idea is (Caller A) calls (Twilio Number). Twilio stores Caller A's number until a second caller is achieved.
Once (Caller B) calls the same (Twilio Number) he is connected to Caller A.
This is at random, and handling many requests at the same time. Once Caller A and Caller B are connected, their numbers are removed from the storage so nobody else will be connected with them.
Rinse repeat.
Twilio developer evangelist here.
You can do this using Enqueue and <Queue>. First you need to create your queue using the REST API. This can be done ahead of time.
I'm going to use Ruby for the example here, however you can see what this looks like in other languages in our documentation.
require "twilio-ruby"
client = Twilio::REST::Client.new(ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"])
queue = client.queues.create(:friendly_name => "call_roulette")
puts queue.sid
You'll need to save the Queue Sid and friendly name, you'll use them to connect to the queue later.
Then, when a person calls you need to check whether there is anyone in the queue waiting. If there is then you connect the two callers, if there isn't then you place that caller into the queue and wait for another call.
When the call is made, Twilio will send an HTTP request to the URL you supply in the Twilio console. You need to respond with the correct
based on the conditions above.
This example uses Sinatra as the web framework.
require "twilio-ruby"
require "sinatra"
client = Twilio::REST::Client.new(ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"])
post "/call" do
queue = client.queues.get(QUEUE_SID)
if queue.current_size == 0
twiml = "<Response><Enqueue>#{QUEUE_FRIENDLY_NAME}</Enqueue></Response>"
else
twiml = "<Response><Dial><Queue>#{QUEUE_FRIENDLY_NAME}</Queue></Dial></Response>"
end
return twiml
end
When the queue is empty, we use Enqueue to put the caller in the queue, when the queue has someone in it, we use Dial and Queue to dial the person in the Queue.
Let me know if that helps at all.

With Twilio, can you get a notification when a queue add/removes a member?

I'm trying to do some server side queue management with a an application I am writing, using Twilio (C# MVC project). Is there any way to receive a notification of some sort when a caller is added to or removed from a queue without constantly having to check the queue myself?
Twilio evangelist here.
I'd suggest looking into using the waitUrl and action parameters on the [<Enqueue>][1] verb.
The url provided in the waitUrl param is requested when the user enters the queue. The url in the action parameter is requested when the caller leaves the queue.
I wrote a blog post a while ago that shows how to create a dashboard un ASP.NET MVC that displays current queue size and average time in queue using those two parameters. It should be pretty straight forward to adapt the post to whatever language and framework your working with.
Hope that helps.

Notify agent when any caller entered in twilio queue

I am using Twlio Client for my application.
I want to notify agent when any caller comes in Queue.
Right now I am calling Rest API Method for Dequeue first member of the queue on every 5 second.
but It is having some performance issues.
Is there any way to notify agent when caller enters in queue?
Twilio evangelist here.
I think a lot of this depends on the specific experience you want to give your agents.
The simplest solution could be to leverage the part of your application that generates the TwiML containing the <Enqueue> verb (putting the caller into the queue). As part of that generation process you could add some code that uses a technology like socket.io or signalr to sent a real-time notification to the browser client telling the agent that a new caller has just been enqueued.
Hope that helps.

Resources