Create a seamless customer service experience by building an IVR Phone Tree for your company. IVR's give the power back to your customer and allow you to serve up common requests immediately and on the fly.
In this tutorial, we'll learn how a company like Home Depot might implement an IVR for their customers. Scroll down this page to get started!
IVRs (interactive voice response) are automated phone systems that can facilitate communication between callers and businesses. If you've ever dialed your credit card company to check on a balance after responding to a series of automated prompts, you've used an IVR. Learn how to build an IVR in minutes using Twilio's powerful TwiML API.Start Tutorial
Stranded aliens can call a phone number and receive instructions on how to get out of Earth safely, or call their home planet directly. In this tutorial, we'll show you the key bits of code to make this work.
To run this sample app yourself, download the code and follow the instructions on GitHub.
Let's get started! Click the right arrow above to move to the next step of the tutorial.
To initiate the phone tree, we need to configure one of our Twilio numbers to send our web application an HTTP request when we get an incoming call.
Click on one of your numbers and
configure the Voice URL to point to our app. In our code the route
action parameter takes an absolute or relative URL as a
value — in our case, the
When the caller has finished entering digits Twilio will make a
GET or POST request to this URL including a
Digits parameter with the number our caller chose.
After making this request, Twilio will continue the current call using
the TwiML received in your response. Any TwiML verbs occuring after a
are unreachable, unless the caller enters no digits.
This route handles processing the caller's input. We first attempt to lookup the TwiML for a given option and respond accordingly.
If our caller chooses '1' for directions, we respond with TwiML
directions to our caller's extraction point. We use the private
_getReturnInstructions method (defined below) to achieve this.
If the caller chooses '2' to call her home planet, then we need
to gather more input from her. We respond with TwiML to handle
this using the private
_getPlanetsMenu method, which we'll
discuss in the next step.
If the caller enters anything else we respond with a TwiML
Redirect to the main
If our caller chooses to call her home planet we will tell her the planet directory. This is akin to a typical "company directory" feature of most IVRs.
In our TwiML response we again use a
Gather verb to receive our caller's
action verb points this time to the
planets route, which
will switch our response based on what the caller chooses.
Let's look at that route next.
In this route, we grab the caller's selection off the request and store
it in a variable called
$selectedOption. We then use a
Dial verb with
the appropriate phone number to connect our caller to her home
The current numbers are hardcoded, but they could also be read from a database or from a file.
That's it! We've just implemented an IVR phone tree that will delight and serve your customers.
If you're a PHP developer working with Twilio, you might enjoy these other tutorials:
Instantly collect structured data from your users with a survey conducted over a voice call or SMS text messages. Learn how to create your own survey in PHP.
Convert web traffic into phone calls with the click of a button.
Thanks for checking out this tutorial! If you have any feedback to share with us, we'd love to hear it. Tweet @twilio to let us know what you think.