Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diverting twilio call to voicemail if unanswered

Tags:

twilio

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?
like image 864
kajham Avatar asked Dec 08 '15 00:12

kajham


People also ask

Can you forward certain calls to voicemail?

Manage your call interactions more efficiently. You can: Forward calls from specific contacts to your linked phone numbers or directly to voicemail.

Does Twilio do ringless voicemail?

Ringless Voicemail is against Twilio's Acceptable Use Policy, specifically our clauses around short duration calls prohibit the double-call approach. It's also illegal in some jurisdictions. Instead, consider using our AMD service to detect if you reach a person or voicemail, then leave a recording or say a message.

Does Twilio have call forwarding?

It's easy to forward your Twilio calls anywhere in the world. Whether you're an experienced developer, or have never written a line of code, we have a number of versatile products to help you get up and running quickly.


1 Answers

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.

like image 83
philnash Avatar answered Oct 23 '22 14:10

philnash