Twilio custom call routing - twilio

I'm looking to implement a custom call routing function for customers dialing a set of company phone numbers for a sales organization using Twilio. Roughly speaking, I want to do something like the following:
When an incoming call is received, based on the called number (i.e. which twilio number was dialed), lookup a different routing algorithm to decide how to route the call.
Routing algorithm will have a number of specific steps, some of which would be like these:
lookup calling number in sales database, if already assigned then route call to assigned agent
lookup "agent on duty" in shift database, if agent is on-shift then route call to agent on duty
simultaneous ring multiple agents, first agent (if any) to pick up and "dial 1 to accept" gets connected to caller
dial a specific agent
fallback to voicemail
For all these cases we want to "whisper" some caller information to the agent, and optionally present a challenge like "dial 1 to accept call" and gather a response before they are connected
We also want to record calls (and preannounce "this call may be recorded..."
Looking at the Twilio API it seems like there might be a few different high-level approaches, for instance:
Implement my own routing logic, and at each step (potentially) initiate a new twilio outbound call to the agent, present a challenge, gather digits, and connect to caller if agent accepts the call
Implement Twilio Queues - probably place incoming caller in queue, step through routing table until we find an agent (or voicemail), and then pull caller out of queue and connect them
Implement Twilio Queues + TaskRouter - as above, but use Task Router to specify my call routing algorithm.
There will not be a high volume of calls, so queuing wouldn't necessarily be my natural choice, but it is possible there might be a few simultaneous calls at any point. I'm more thinking that queuing might be useful in that it's designed to handle this workflow - specifically accept call, play music/message/ring while we locate an agent, then connect the agent to the queued call.
In general would like some guidance on which path to take - not sure whether Task Router will be flexible enough to handle my call routing (i.e. can I use decision logic based on external database queries, API calls, etc to make task routing decisions). Also, if I choose to do all of this myself (i.e. no queues, task router), then it wasn't clear to me how to "connect" two separate Twilio calls together (i.e. the inbound caller "call" and the outbound "call" to the agent) - do I need to create a twilio conference?
I'll be implementing this in python, but any references to similar implementations in any language would be helpful...
Thanks in advance!

Related

Twilio Cold Transfer, no queue overflow

Requirement
Our business requires us to expand the functionality of the transfer feature that is already built in to
Twilio Flex.
What exists today
Today's functionality (out of the box) is partially what we need with the Actions.TransferTask functions. The issue with this is that when we choose an agent to cold transfer to, and they're not available, the call gets put back in to a queue and picked up by the next available agent. This seems completely counter intuitive to how I would expect it to work as I would expect that call to go to voicemail if the agent is unable to pick up.
What we tried
We have logged a support ticket with Twilio to no avail. Any attempts to use the StartConferenceCall won't work because we're on an active call. Twilio functions' Dial doesn't seem to work as I don't seem to have access to my current call. (Dial is meant for calls that are about to happen?) But Dial seems to be the only process that allows digits to be passed. Therefore, conferences & participants don't seem to be the answer either.
What we do have though is a phone number that will end up in our primary work flow and if the incoming number is the aforementioned number, we skip the voice prompts, accept digits and redirect to the agent. This part works.
What we need
We're looking for a Twilio function or plugin Action (or some other method that I'm unaware of) that can cold transfer a call to another agent with no over flow to a queue (let it get picked up by voicemail).

Twilio: Is it possible to call multiple client id at once?

I have implemented warm transfer in the my application (C#) but I have to extend it.
Below is my new use case:
Customer calls to our Twilio number. That Twilio number is assigned to a department in our database. Based on that number I retrieve all agents in that department. So, I want this call to go to all the agents in that department and all agents can see an incoming call on their screen.
How can I make a call to multiple agents on their 'client id' (they have generated their capability token with)?
PS: I can't use dial because dial is used for conference once agent picks up the call, I have to do something in CallResource.Create() function in C#
Twilio developer evangelist here.
If you can't do this via <Dial>, you need to loop through all the numbers you want to call within your C# code, calling CallResource.Create() for each of them.
Note, you will likely want to setup to receive statusCallback webhooks so that you can complete the other calls if someone has answered.

Ring group: associate ensuing calls with initial call

So my call app has a 'ring group' functionality. The idea being that certain numbers should fan the call out to multiple ring group members. Twilio has an article which describes this process here:
https://www.twilio.com/blog/2009/05/dialing-multiple-numbers-simultaneously-with-twilio.html
I want to do something similar. Loop through my available ring group members and do a dial.number to each of them. This would create a new call to each one of them that hits our regular incoming call webhook. Works great except if no one answers then the call will be sent to a random members voicemail.
I thought of a couple strategies to possibly fix this but none are quite working:
Manage the timeouts. Set the timeout of the dial for the ring group to something shorter than the timeouts for our incoming call webhook. My thought was this might skip the after action on the incoming calls and go to the after action on the ring group - which is a ring group voicemail box. But in this case setting the timeout on the ring group dial doesn't do anything. Only the timeout on the incoming call webhook is being respected.
Pass some context. If I could pass additional params from the ring group call through the dial.number method then I could recognize in the incoming call webhook that this is coming from a ring group and act accordingly. But apparently you cannot pass custom params. It seemed the only thing I could change was the callerId - which I could use to indicate the ring group number but then I lose the context of who the call is coming from.
Attach a status_callback. I could put a status_callback on the dial.number in the ring group. Once the call is initiated it will post to me with a CallSid. I could use this sid to look through the calls created by my incoming call controller and link up the sids thereby identifying which calls are from a ring group. Unfortunately the CallSid i get on the status_callback for the ring group dial.number does not match any other sid that my app receives. The sids on the incoming call webhook are distinct - and if I fan it out to multiple members interestingly each incoming call webhook gets a different sid. I initially thought that since there was only one leg connected to the incoming call that they would all share the same sid...
I wonder if anyone has any other ideas?

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?

Attended Call Transfer in Twilio

I am trying to create an attended transfer using Twilio.
The flow I would like is as follows:
1. Existing call with two legs (client side, agent side)
2. Using API put Client on HOLD and put Agent 1 in Conference
3. Using API Put Agent 2 into same Conference
4. Agent 1 and Agent 2 can speak without Client hearing
5. Using API add Client to Conference
6. Client, Agent 1 and Agent 2 can speak together
7. Using API Agent 1 can be disconnected from the call
Is it possible to do this?
Or do we need to create a conference for all our inbound and outbound calls?
(even though only about 5% of our calls get transferred)
Twilio developer evangelist here.
You can definitely do this. It might be easier to do this from the context of a conference in the first place, as you can take advantage of putting conference participants on hold.
To do it from a regular call to start with, you would want to redirect one of the agent or caller to new TwiML and then make sure the other leg of the call had somewhere to continue to with the existing TwiML. It's probably easier to transfer the agent's call with the REST API and then make sure that the TwiML you originally return to the user continues to place them into a queue using <Enqueue> that you can then call them out of later, or simply a looping <Play>.
Let me know if that helps at all.

Resources