How can I handle reaching voicemail using Twilio's <dial> verb - twilio

I know that on making a call Twilio can detect an answering machine, and react differently.
However if I use the <dial> verb, there's no obvious place to add this feature, even though it's essentially the same thing.
My intended flow is:
Customer enters their phone number
Twilio calls Customer and plays a voice message
Twilio dials an agent number, likely a mobile
If the Agent picks up, connect the customer to the agent
If the Agent busies the call or does not answer, call will likely go to Agent's voicemail.
Terminate call to Agent
Record voicemail from Customer
Email voicemail to Agent

From the official docs on the <Dial> verb (emphasis mine):
This is the simplest case for Dial. Twilio will dial 415-123-4567. If someone answers, Twilio will connect the caller to the called party. If the caller hangs up, the Twilio session ends. If the line is busy, if there is no answer, or if the called party hangs up, <Dial> exits and the <Say> verb is executed for the caller before the call flow ends.
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_dial.xml -->
<Response>
<Dial>415-123-4567</Dial>
<Say>Goodbye</Say>
</Response>
Placing a <Record> verb after the <Say> verb sounds like what you are looking for. You can change the timeout from the default value of 30s like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial timeout="9001">415-123-4567</Dial>
<Say>Please leave a message</Say>
<Record action="/process_new_voicemail" />
</Response>

I am sure this is late, but hopefully it helps some one out. It sounds like you may just need to screen the call.
Basically, you can ask the "agent" that you dialed to accept the call and hang up if you do not receive input.
I am not sure what language you are using, but here is a great php/Laravel tutorial to explain:
https://www.twilio.com/docs/tutorials/walkthrough/ivr-screening/php/laravel
The key part is here:
$dialCommand = $response->dial(
['action' => route('agent-voicemail', ['agent' => $agent->id], false),
'method' => 'POST']
);
$dialCommand->number(
$numberToDial,
['url' => route('screen-call', [], false)]
);
Notice that the dial command uses the 'action' to specify a location that is sent a POST request should the call end i.e POST to /agent-voicemail.
Then, the number is dialed along with a 'url' parameter this is the location that will be requested after the agent has picked up but before connecting the two parties.
The /screen-call route then asks the agent to accept the call, if no input is received it hangs up and will make a POST request to the initial setup /agent-voicemail route.
This method will handle your scenario because if it goes to voicemail no input will be received and the call will end.

Related

simulring and collect digits from dialed number to accept call

We've got a basic twiml set up that sends a call to multiple destinations, it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>+1800XXXXXXX</Number>
<Number>+1912XXXXXXX</Number>
</Dial>
</Response>
The problem is I want to have one of the destination parties press a digit ( like "1" for example ) before twilio actually bridges the call to them.
I've looked at but that only seems to get digits from the caller, not the callee.
Twilio developer evangelist here.
To have the recipient of a call started by a <Number> perform an action, you need to provide a URL as the url attribute of the <Number>. When the call connects, Twilio will make a webhook request to that URL and you can return TwiML from the URL. Within that TwiML you can include a <Gather> to have the recipient enter a digit before you connect the call. See the documentation for the url attribute for <Number> for more detail.

Twilio call forwarding one after another - how to disconnect if person picks up the call

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say> Connecting call to Pinto </Say>
<Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
<Number>XXXXXXXX</Number>
</Dial>
<Say> Pinto is not picking up the call, now connecting call to Management </Say>
<Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
<Number>XXXXXXXX</Number>
</Dial>
<Say> No one is picking up right now. Please text us at +12022171828 </Say>
</Response>
Above is the call forwarding flow for one after another.
What I'm looking here is,
If 1st user attended the call, then it should not initiate the call to 2nd number and also it should not say text message which is at last line
If 1st user disconnected, then redirect call to 2nd number - if 2nd number not picking up the call then it should say text message which is at last line
if 1st user disconnected, then redirect call to 2nd number - if 2nd number picked up the call then it should not say text message which is at last line
Also I want to Implement Transcribe & Transcribe call back by using TwiML.
So, please help me like how we need to do with that?
To carry out this flow, you cannot perform the entire thing in one TwiML response. Instead, you will need to provide the <Dial> element with URL in the action attribute so that once the first call completes, Twilio makes a webhook to find out what to do next.
So, your first TwiML response should look like:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say> Connecting call to Pinto </Say>
<Dial record="record-from-answer" timeout="10" hangupOnStar="true" action="/complete">
<Number>XXXXXXXX</Number>
</Dial>
</Response>
Above I've added action="/complete" to the <Dial> and this means we need an application to be able to respond to HTTP requests to /complete as well. We also need this to be an application and not a static response as we need to work out whether the call was answered or not and decide on what to do next and what TwiML to respond with.
We can do this because one of the parameters that Twilio sends to the action URL is DialCallStatus. This parameter can be "completed", "busy", "no-answer", "failed" or "canceled" and this tells you what happened in that first call.
So, in your case, you will want to check the DialCallStatus and if it is "completed" then you do not need to return the next <Say> and <Dial>. If, however, the DialCallStatus is one of the other statuses, you do want to return the next <Say> and <Dial>. That <Dial> should include another action URL that makes the same choice at the end of the second <Dial>.
I'm not sure what language you are building with, but a pseudo-code idea of this would look like this:
post '/complete' do
if params["DialCallStatus"] != "completed"
return "<Response><Hangup/></Response>"
else
return "<Response><Say>Pinto is not picking up the call, now connecting call to Management</Say><Dial ....></Response>"
end
end

Twilio: Responding to a caller after transcript for previous response is received

I'm trying to get the following flow to work:
Caller dials twilio #
We ask a question of the caller and they respond by speaking
Once the transcript is received (not the audio file), we respond by asking them another question... this goes on for 2-3 questions
The problem I'm having is the separation of the calls to the main webhook handler, and the transcript handler.
I have the primary call handler responding with the first question, as follows:
<!-- [/ handler] initial response, with the first question -->
<Response>
<Say voice="alice">What is your favorite color? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcript" maxLength="60"/>
</Response>
Then we receive a second request to the primary call handler when the recording is completed. I can't respond with another question yet (business requirements), so we respond with a vague confirmation:
<!-- [/ handler] vague confirmation response
<Response>
<Say voice="alice">Got it. Give me a couple seconds to write that down.</Say>
</Response>
Then I receive a hit on the /transcript handler with the transcript, to which I respond with:
<!-- [/transcript handler] Second question -->
<Response>
<Say voice="alice">What is the air-speed velocity of an unladen swallow? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcription" maxLength="60"/>
</Response>
But apparently you can't respond to that handler with TWiML? The caller is hung up on after the second response from the / handler.
Any ideas on how I can implement this? I don't think I can really have the user wait in silence before responding to the second / handler request...
When you receive a hit on your /transcript handler you have in the request the callSid (CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX) among other parameters.
With this callSid you can modify the "in progress call" my making a request to Twilio and passing a new TwiML.
Not sure what language are you using on your server side but in Node.js would look something like this:
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);
client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.update({twiml: '<Response>
<Say voice="alice">What is the air-speed velocity of an unladen swallow? Press any key when done.</Say>
<Record transcribe="true" transcribeCallback="/transcription" maxLength="60"/>
</Response>'})
.then(call => console.log(call.to));
Docs: (https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-node-js)
Twilio developer evangelist here.
While you seem to have got this version of your call flow working, it is not the best way of approaching this issue as we now have <Gather input="speech">.
<Gather> with the input set to "speech" will transcribe the user in real time, delivering the SpeechResult to your next webhook URL (the action attribute). This way you don't need to wait while the transcription is performed asynchronously and can respond with TwiML immediately.
Using <Gather> like this would let you build a call flow like:
<!-- [/ handler] initial response, with the first question -->
<Response>
<Gather action="/question2" input="speech">
<Say voice="alice">What is your favorite color?</Say>
<Gather>
</Response>
Then in /question2 you can dynamically read the response straight away. Here's how you could respond using Ruby and Sinatra as an example server side language:
post "/question2" do
favorite_color = params["SpeechResult"]
response = "Great, I love the color #{favorite_color} too. Now, what's your favorite pet?"
return "<Response>
<Gather action="/question3" input="speech">
<Say>#{response}</Say>
</Gather>
</Response>"
end
And so on. You should find it a much better experience than using <Record> with transcription.

Twilio, How to transfer a in-progress call to another number

How to transfer a in-progress call to another number.The concept that I m using is to use the update method when the call is in in-progress and dial the number that I wanted To connect and It is working but the connection with the first caller is breaking/
Code for the process of transferring call-
1.process for dialing call-
<Response>
<Dial callerId="callerid">
<Number statusCallbackEvent="initiated ringing answered completed" statusCallback="urltohadlestatus">user_number</Number>
</Dial>
</Response>
2. process to process to transfer the call-
I have used the update method to transfer the call.
function update_call1($CallSid, $admin_no) {
$rr = array(
"url" => "trurl?admin_no=".$admin_no,
"method" => "POST"
);
$call = $this->client->calls($CallSid)->update($rr);
return $call->to;
}
and used this TwiML
<Response>
<Dial>admin_number_call_to_be_transfered</Dial>
</Response>
what this does is transfer the call but when admin receives it,It disconnects the call.
And what I need like when jack make call to jenny and now jack want to transfer the call to jhonny and when call is transferred to jhonny, jack shound be disconnected from the call.
Twilio developer evangelist here.
You have two options here. Once the call is transferred away, the other caller will drop if it has nothing else to do. There are two ways you can achieve this.
You can either put the callers in a <Conference>. Then when the caller is transferred the other call remains in the conference room. There is a good tutorial on warm transfers using this technique, which might help.
Alternatively, if the side of the call that is dropping out right now is the one that generated the call from the Twilio REST API you can add more TwiML below the <Dial> verb to have the call continue. For example:
<Response>
<Dial>OTHER_NUMBER</Dial>
<Say loop="0">You are still on the call.</Say>
</Response>
Will just keep saying "You are still on the call" once the other end is transferred away.
You can also achieve this with the action attribute for <Dial>. Using the action attribute means that Twilio will make a webhook request to the URL you specify and use the TwiML from that response to carry on the call.

Twilio unable to forward/transfer call

I have an app that dials a phone number, gives a set of instructions, and then forwards the call to a specified phone number. Currently when I press the digit to transfer the call it just pauses and hangs up. Not sure what im doing wrong.
This is the initial instructions. If the number 1 is pressed it is supposed to transfer to transfer.xml, which is under # 2.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather timeout="10" action="http://1.1.1.1/twimlet/transfer.xml" numDigits='1' finishOnKey='1'>
<Say>"Dummy Text Dummy Text"</Say>
<Say>"Please press 1 to transfer this call. Or nothing to hang up."</Say>
</Gather>
</Response>
If the caller presses #1 then it is supposed to send them to this xml file, and transfer the current call to the number under dial. But currently it just hangs for 2 seconds and drops the call.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>"Transferring you to a court clerk"</Say>
<Dial timeout="60" callerID='+14393523419'>
<Number>8125277222</Number>
</Dial>
</Response>
Am I doing something wrong with my xml? Not sure why it is dropping.
Twilio developer evangelist here.
Your action in your <Gather> is pointing towards the URL http://1.1.1.1/twimlet/transfer.xml. That looks like a local network address rather than a publicly available URL. If that IP address is not available to Twilio, then the call will not be able to continue.
Try using relative URLs instead of absolute ones. Twilio will happily follow the path /twimlet/transfer.xml.
Let me know if that helps!
Hm could it be because finishOnKey is set to 1 in your <Gather> verb? So, it's taking it as you end the call? Have you tried setting it to finishOnKey=""?

Resources