Phone Menu App

An IVR (Interactive Voice Response) system is also known as phone menu system. It is an automated phone system that interacts with a caller via pre-recorded or dynamic text-to-speech messages and inputs, via the keypad.

IVR systems are popular as they can handle large call volumes and help reduce the costs associated with customer service. With our app, you can build an entire phone menu system on the Plivo platform (in any computer language), without relying on expensive physical infrastructure.

The instructions below will teach you how to build your own IVR system that can:

  • read a random joke (from Reddit) if ‘1’ is pressed
  • play a song if ‘2’ is pressed
  • say “Sorry, I didn’t catch that. Please hang up and try again later.” if nothing is pressed

The app will operate in the following sequence:

  1. The user dials the Plivo IVR phone number.
  2. The user is prompted with the message “Welcome to the Plivo IVR Demo App. Press 1 to hear a random joke. Press 2 to listen to a song.”
  3. During the call, if the user presses ‘1’, then Plivo reads a random joke from Reddit. If the user presses ‘2’, then Plivo plays a song.
  4. If anything else is pressed or if the user does nothing, then Plivo says “Sorry, I didn’t catch that. Please hang up and try again later.” and hangs up.

Note: We use Python in this tutorial, but you can write your apps in any programming language. Check out Plivo’s pre-built Helper Libraries for details.

Prerequisites

  1. Sign up for a free developer trial account at Plivo.com.

  2. Head over to the Heroku documentation, setup an account, and install the Heroku toolbelt.

    Note: You may also use your own servers, but to simplify things, we will use Heroku.

Get the application source code

  1. Clone the source files from github by typing the following command into your console:

     git clone https://github.com/plivo/phone-ivr-python.git
    
    Note: If you don’t already have pip installed, you'll want to follow this guide.
  2. Run the app locally. In your console, navigate to the folder phone-ivr-python and run the app, by typing the following into your console:

     cd phone-ivr-python
     virtualenv --distribute venv
     source venv/bin/activate
     pip install -r requirements.txt
     python app.py
    

Understand the XML

When a call comes in, the XML is what controls the call and tells Plivo what to do with that call. The two XML elements we use here are <GetDigits> and <Speak>. <GetDigits> recognizes the digits pressed during the call as an HTTP request to perform the action specified in the action URL, while <Speak> reads the text that’s specified.

Click http://localhost:5000/response/ivr/ to access your app XML and verify it the same XML as shown below.

<Response>
    <GetDigits action="http://localhost:5000/response/ivr" method="POST" numDigits="1" retries="1" timeout="10">
        <Speak>
            Welcome to the Plivo IVR Demo App. Press 1 to hear a random joke. Press 2 to listen to a song.
        </Speak>
    </GetDigits>
    <Speak>
        Sorry, I didn't catch that. Please hang up and try again later.
    </Speak>
</Response>

Deploy your app on Heroku

Create a Heroku app by typing the following commands into your console:

heroku create
git push heroku master
heroku scale web=1
Your output should look like the following. Make a note of your Heroku app URL. In this case, the Heroku app URL is http://pacific-chamber-7397.herokuapp.com/
Creating pacific-chamber-7397... done, stack is cedar
http://pacific-chamber-7397.herokuapp.com/ | git@heroku.com:pacific-chamber-7397.git
Git remote heroku added

Type your Heroku app URL in your web browser to verify that your app is working.

Create a new Plivo application

  1. Sign into your Plivo account.

  2. Create a Plivo application by clicking on the ‘New Application’ button in the Applications tab.

  3. Give a name to your application (next to Application Name), lets call it ‘Phone IVR’.

  4. Fill in the Answer URL field with your Heroku app URL appended by /response/ivr/

    For example, our Answer URL will look like this:

     http://pacific-chamber-7397.herokuapp.com/response/ivr/
    
  5. Choose the GET Answer method and leave all other fields as is. Click on ‘Create’ to save.

Phone IVR App

Assign a Plivo phone number to your app

  1. Go to the Numbers tab and select the phone number you want to use for this app. If you don’t have a number, click on the Buy Number button to purchase one.

  2. Then select ‘Phone IVR’ (name of the app) from the Plivo App dropdown list.

  3. Click ‘Update’ to save.

Edit Number

Call your Plivo phone number to see how the IVR application works.

Is anything on this page unclear? Suggest edits and help us improve our documentation!