Twilio to have pause period when using loop to repeat voice call - twilio

I tried repeating a message in voice call as python code here which was guided here but not working i.e. no pause at all whatever number for :length it is <Pause length="3">
call = client.calls.create(
twiml = f'''
<Response>
<Gather>
<Say loop="{loop}">{message}</Say>
<Pause length="3"></Pause>
</Gather>
<Redirect>/gather.xml</Redirect>
</Response>
''',
to = to,
from_ = from_,
)

Take a look at SSML Pause.
Adding a Pause
SSML Break Tag
I tried out the below, and it worked. Don't forget your <Gather> action url.
<Response>
<Gather>
<Say loop="3">This is a message with a pause between loops<break time="3s"/></Say>
</Gather>
<Redirect>/gather.xml</Redirect>
</Response>

Related

Different Twiml for voicemail

we have a Windows service, that automatically send multiple voice calls for appointment reminders.
var call = CallResource.Create(
machineDetection: "DetectMessageEnd",
asyncAmd: "true",
twiml: new Twiml(message),
to: new PhoneNumber(toPhone),
from: new PhoneNumber(FromPhone));
The message used for the one above is dynamically generated using the Twiml below.
<Response>
<Pause length="1"/>
<Say voice="alice">Hello {name},</Say>
<Pause length="1"/>
<Say voice="alice">Your appointment is scheduled for {date} at {time}.</Say>
<Pause length="1"/>
<Gather timeout="3" numDigits="1" action="https://6f8137e0cb9a.ngrok.io/Voice/gather?aid=12345" method="GET">
<Say voice="alice">To confirm this appointment press 1, to cancel press 2, or you may hang up.</Say>
</Gather>
</Response>
It works fine, when the call is picked up, but if no answer then when it goes to voicemail. I want to send a different Twiml like the one below
<Response>
<Pause length="1"/>
<Say voice="alice">Hello {name},</Say>
<Pause length="1"/>
<Say voice="alice">Your appointment is scheduled for {date} at {time}.</Say>
<Pause length="1"/>
<Say voice="alice">To confirm or cancel this appointment call 18888888888.</Say>
</Response>
Is this even possible with Twilio ?
Twilio developer evangelist here.
That is absolutely possible! In your original script it shows that you are using asyncAmd, which means that your initial message will start playing even as the machine detection goes on. If a machine is detected then the AMD will want to alert you of that.
To do that, you need to provide an asyncAmdStatusCallback parameter to your outbound call that points to a URL that can receive a webhook when you get the result from the AMD.
That webhook will receive paramters including the CallSid and your AccountSid and most importantly the AnsweredBy parameter. When using DetectMessageEnd for your AMD, the AnsweredBy parameter could be any of "machine_end_beep", "machine_end_silence", "machine_end_other", "human", "fax" and "unknown".
For the machine results, if you want to leave a message you will now need to update your call with new TwiML.
var call = CallResource.Update(
twiml: new Twiml(MACHINE_MESSAGE),
pathSid: CALL_SID
);
Let me know if that helps at all.

Using TwiML, how do I use <say> to response to user after dtmf inpu?

I have a simple test application that makes a call, and using TwiML, it asks the user to press 1 or 2. Everything is working great. My action is called, I get by my POST response. The only thing that I would like to do is once the user selects 1 or 2, use to thank them. Currently when entering 1 or 2, the call is just ended.
Here is my current TwiML...
<Response>
<Gather action="doSomething" method="POST" timeout="5" numDigits="1" finishOnKey="#">
<Say voice="woman">Press 1 or press 2</Say>
</Gather>
<Say voice="woman">You did not press anything, goodbye.</Say>
</Response>
Thanks for any help!
In the "doSomething", you would return TwiML, using Say Verb to thank them. When TwiML ends, the call ends.

How to dial the same digit as asked in twilio incoming voice call

I've done the basic twillio client setup following instructions here - https://www.twilio.com/docs/quickstart/php/client/incoming-calls
Would it be possible to reply the voice call with the digit asked to dial ?
Like, if the automated call asks to press 5, I can respond with pressing digit 5, like that ?
Thanks!
Have your gather code like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/process_gather.php" timeout="10" finishOnKey="*">
<Say>Please enter a digit</Say>
</Gather>
</Response>
Then on process_gather.php capture the gathered input and send it back to the user using
<Response>
<Say>You pressed <?php echo $_REQUEST['Digits']; ?></Say>
</Response>

Twillio Call Screening silence on answer

I am using the call screening example at https://www.twilio.com/docs/howto/callscreening
When I place a call to my incoming Twilio number via landline, it is forwarded to my mobile and I am prompted to "press a key to accept"
Problem is that as soon as I answer it on my mobile the incoming call stops getting the ringing tone and has silence until about 5 seconds after I press any key.
As soon as I answer the call on my mobile the user is presented with silence and has the impression that the call has been answered but it is not until I have pressed a key to accept the call and further until Twilio does its hookup of the call, that is the point that I can talk to the person.
Could I present them with music or a ringing tone until the cal really has been connected to me?
Here is the code of the forwarding
<?php
// Set the numbers to call
$numbers = array("<number to call 1>", "<number to call 2>", "<number to call n>");
$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";
$DialCallStatus = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : "";
header("content-type: text/xml");
// Check the status of the call and
// that there is a valid number to call
if($DialCallStatus!="completed" && $number_index<count($numbers)){
?>
<Response>
<Dial action="attempt_call.php?number_index=<?php echo $number_index+1 ?>">
<Number url="screen_for_machine.php">
<?php echo $numbers[$number_index] ?>
</Number>
</Dial>
</Response>
<?php
} else {
?>
<Response>
<Hangup/>
</Response>
<?php
}
?>
And the part that asks me to accept the call
<?php header("content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<Response>
<Gather action="complete_call.php">
<Say>Press any key to accept this call</Say>
</Gather>
<Hangup/>
</Response>
Twilio Customer Support here.
What I would recommend is that you place the incoming caller into conference, this would allow you to use the waitURL parameter to play hold music whilst your agent decides to take the call:
https://www.twilio.com/docs/howto/simple-conference

Twilio, press 1 to listen to your voicemail

I'm trying to build a voicemail inbox feature, but whenever I use twilios voicemail functionality, once the user records after the beep, the call hangs up.
Is there any way to let the user hear what they said before saving it?
Twilio developer evangelist here.
When you use the <Record> verb in TwiML, you should add the attribute "action" with a URL for what to do once the recording is done. That action URL will receive a request once the recording is finished with the attributes of the recording, that is the recording URL and duration and any digits the caller pressed to end the recording.
If you return more TwiML from this action, then the call will continue and you will be able to do things like repeat the recording, like you want.
So, for example (with a pseudo templating language) your <Record> TwiML might be at the path /record and look like:
<Response>
<Record action="/repeat" />
</Response>
Then your /repeat URL would look something like this:
<Response>
<Say>Your message was:</Say>
<Play>{{ recordingUrl }}</Play>
<Gather numDigits="1" action="/choice">
<Say>Press 1 to record the message again or press 2 to save your message</Say>
</Gather>
</Response>
Then finally your /choice action:
<Response>
{{ if Digits == '1' }}
<Redirect>/record</Redirect>
{{ else }}
<Say>Thank you for your message</Say>
<Hangup />
{{ end }}
</Response>
I hope that helps! Let me know if there's any other way I can help.

Resources