Get Started

IVR: Extensions

Adding support for extensions is simple and requires only slight modification to the basic IVR we created in the last section.

Prior Sections

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:

Usage

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.

Concepts

This demo shows how to implement extensions using Twilio's <Gather> verb.

Download

IVR.zip

Implementation

  • 1

    • Our Twilio number's Voice URL is set to handle-incoming-call.xml. When someone calls the number, Twilio will request this page with the standard TwiML request parameters.
    • howtos/ivr/code/ivrs-extensions/handle-incoming-call.xml
      <?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>
          
  • 2

    • The application responds in TwiML to Twilio's request using the Say and Gather verbs. This instructs Twilio to prompt the customer for the extension and gather their input.
    • howtos/ivr/code/ivrs-extensions/handle-user-input.php
      	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>';
      	}
          
  • 3

    • Twilio prompts the user and gathers their input. This input is then sent back to your application as an HTTP request.
  • 4

    • Your server processes the customer input and connects the caller to an agent.

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: