Building off the basic IVR we created in the last sections, we can easily add features commonly found in sophisticated IVRs, such as call screening (often referred to as "whisper") and recording.
This is part three of a five part series on building IVRs using Twilio's API. If you're just joining us, you can find links to the prior sections below:
When a customer dials into our IVR and decides to speak to an agent, the call is forwarded to the agent's desk phone. Before the calls are connected, the caller is informed that the call will be recorded, and the agent is given the option to accept or reject the call.
Fun fact: this method of speaking or prompting one caller without the other hearing is called "whispering".
This demo shows how to implement call screening and recording using Twilio's <Dial> and <Number> verbs.
handle-incoming-call.xml. When someone calls the number, Twilio will request this page with the standard TwiML request parameters.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="handle-user-input.php" numDigits="1">
<Say>Welcome to TPS.</Say>
<Say>For store hours, press 1.</Say>
<Say>To speak to an agent, press 2.</Say>
<Say>To check your package status, press 3.</Say>
</Gather>
<!-- If customer doesn't input anything, prompt and try again. -->
<Say>Sorry, I didn't get your response.</Say>
<Redirect>handle-incoming-call.xml</Redirect>
</Response>
else if ($user_pushed == 2)
{
echo '<Gather action="handle-extension.php" numDigits="1">';
echo "<Say>Please enter your party's extension.</Say>";
echo '<Say>Press 0 to return to the main menu</Say>';
echo '</Gather>';
echo "<Say>Sorry, I didn't get your response.</Say>";
echo '<Redirect method="GET">handle-user-input.php?Digits=2</Redirect>';
}
$user_pushed = (int) $_REQUEST['Digits'];
echo '<Say>Connecting you to agent 1. All calls are recorded.</Say>';
echo '<Dial record="true">';
echo '<Number url="screen-caller.xml">+1NNNNNNNNNN</Number>';
echo '</Dial>';
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="handle-screen-input.php" numDigits="1">
<Say>You have an incoming call.</Say>
<Say>To accept the call, press 1.</Say>
<Say>To reject the call, press any other key.</Say>
</Gather>
<!-- If customer doesn't input anything, prompt and try again. -->
<Say>Sorry, I didn't get your response.</Say>
<Redirect>screen-caller.xml</Redirect>
</Response>
<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response>';
$user_pushed = (int) $_REQUEST['Digits'];
if ($user_pushed == 1)
{
echo '<Say>Connecting you to the caller. All calls are recorded.</Say>';
}
else {
echo '<Hangup />';
}
echo '</Response>';
?>
This is part three of a five part series on building IVRs using Twilio's API. When you're ready continue on to the next section: