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.
Related
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.
I'm building an app where I have Twilio make a call, 'gather' the response from the callee and keep calling my backend because of the <Gather>.
However, I also want to be on the call live to hear what's happening in realtime. I was wondering if I can do this by using the Dial verb in conjunction.
This is what my flow looks like:
Twilio calls my server to get TwiML for a call it just made
Server returns a <Gather> response
Twilio calls server again with the data it 'gathered'
Server returns another <Gather> in response
...and so on.
This is what I'm trying to do:
(NEW:) I use webhooks to dial into a conference call 'C1'
Twilio calls server to get TwiML for a call it just made
Server returns a <Dial> followed by the gather response as earlier. I wanted the <Dial> to put the active call in the same conference C1 that I've already joined from another phone so I can listen to what's happening on the call.
Twilio calls server again with the data it 'gathered'
Server returns another <Gather> in response
...and so on.
So, what I'm trying to do here is to be on the conference before any of this happens so I can listen to Twilio interact with callee.
But looks if I try to append <Gather> to a <Dial> in a TwiML response, Twilio doesn't start 'gathering' from the conference call, but instead, waits for the conference call to finish first and only then execute the 'gather'.
PS: The closest approximation to what I want to do is set the record flag on beforehand when Twilio makes the call to the callee, and then listen to the entire conversation later to figure what happened but that's incredibly inefficient.
How can I help myself?
This is what my code looks like:
Gather g = new Gather.Builder().input("speech")
.action(BASE_URL + "/processSpeech?")
.timeout(4)
.build();
Conference.Builder conferenceBuilder = new Conference
.Builder("confie")
.startConferenceOnEnter(true)
.endConferenceOnExit(true)
.waitUrl("");
tmlb.dial(new Dial.Builder().conference(conferenceBuilder.build()).build());
VoiceResponse.Builder tmlb = new VoiceResponse.Builder();
TwiML tml = tmlb.gather(g).build();
Twilio developer evangelist here.
You can't use <Gather> within the context of a <Conference> so this flow is not possible. I'd suggest that you record the call and listen back to find out what happened. Though you say that is less efficient.
I'd like to help further, but I'm not sure what the exact use case here is. Perhaps you could share a bit more of what you are trying to achieve and I can update this answer?
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?
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.
We are setting up a call center using Twilio.
At the end of the greetings and menus, our users are redirected to a queue waiting for the next available agent.
We would like the system to:
- Call automatically the next available agent. This is to prevent the agent from dialing the queue to know if users are waiting.
- Be able to change the order of the queue. Our users have different priorities.
How can we get this done? What are the best practices?
FYI: We are using PHP, TWIML and we DO NOT have our own IPBX (Not able to use SIP Protocol).
Thanks,
Dimitri
Twilio evangelist here.
There are a few ways you could do this, but my suggestion would be to use the action attribute of the Enqueue verb.
The action attribute lets you tell Twilio about a URL that you want it to request when a caller leaves the Queue. As part of this request, Twilio will pass you a parameter named QueueSid. Using the QueueSid, you can make a request to Queues endpoint in the Twilio API, see if the current_size of the Queue is greater than zero, and if it is initiate a call out to the next available agent.
Hope that helps.