Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forwarding an incoming call to multiple numbers using call screening without round robin

Background

I'm attempting to implement call screening for my twilio app - i.e. a person presses a key to accept a call. I have seen a couple of examples of this in action (e.g. How to use twilio to guarantee a live answer or voicemail?) however the given answers for the case of forwarding a call to multiple numbers uses a round robin method.

The question

Is there a way to have everyone called at the same time and the first person that gets through the challenge speaks and all other calls disconnect?

Why?

I would like to do this because an incoming caller will need to potentially wait for quite some time if the call is only answered by the last person in the round robin.

like image 544
user714852 Avatar asked Dec 12 '22 11:12

user714852


1 Answers

Twilio Evangelist here,

When you receive your initial call (let's call it the customer) ask the them for some information using <Gather>, or play them some holding music, whatever you think works best:

<Response>
  <Play loop="0">/my_music.mp3</Play>
</Response>

Then, use the REST API to initiate 3 outbound calls to what we'll call the agents. You need to be mindful of Twilio's rate limit. Each of these call would have TwiML along these lines:

<Response>
   <Gather numDigits="1" action="/accepted">
     <Say>Incoming call from +X YYY ZZZZ ZZZZ</Say>
   </Gather
<Response>

Now, as soon as one of the agents presses a key (you may of course want to add options to reject etc) they will be redirected to the action URL. On your sever, you need to respond to the first agent with:

<Response>
  <Dial>
    <Conference>some-unique-room-name</Conference>
  </Dial>
</Response>

You then need to make a request to the REST API and change the customers inbound call (who is still listening to music for example) and use the above TwiML to put the customer into the same conference room as the agent.

When any of the subsequent agents decide to accept the call, they are redirect to the /accepted URL, but because your application already knows that customer has been connected to another agent, you can just play them a message saying the call is already being responded to.

There are ways you can expand on this. For example using the <Queue> TwiML verb to handle multiple incoming calls more easily.

You may also want to take a look using a 'whisper' with the url attribute of the <Number> verb. This allows you to add an extra TwiML document that would only be executed on the agents side. Although you use multiple <Number> verbs only the first agent to answer will hear the whisper.

<Response>
  <Dial>
    <Number url="/whisper">+AGENTNUMBER</Number>
  </Dial>
</Response>

The /whisper TwiML can contain a <Gather> asking the agent to accept the call. Once the call reaches the end of a TwimL document, it connects them to the calling Customer. Otherwise you can use <Hangup> to reject.

There is Python code for most of this on the links provided. I'm afraid I'm not much of a Python coder, but I'm guessing the TwiML helps?

Good luck!

like image 107
xmjw Avatar answered Dec 28 '22 08:12

xmjw