Adding support for extensions is simple and requires only slight modification to the basic IVR we created in the last section.
This is part two 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 customers dial into our IVR and decide to speak to an agent, we ask them for the agent's extension. The call is then directed to the agent specified.
This demo shows how to implement extensions using Twilio's <Gather> verb.
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'];
else if ($user_pushed == 1)
{
echo '<Say>Connecting you to agent 1.</Say>';
echo '<Dial>+1NNNNNNNNNN</Dial>';
}
This is part two of a five part series on building IVRs using Twilio's API. When you're ready continue on to the next section: