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:
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
Manage your call interactions more efficiently. You can: Forward calls from specific contacts to your linked phone numbers or directly to 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With