TL;DR version of the guide

You'll need to do the below steps and then copy the entire code is avaible below to be run on your server.

The full code


      

If you get stuck somewhere, these are the steps, so you can do some troubleshooting


How to build an IVR application with Flask

What we want to accomplish in this tutorial

  1. Set up a listening server that the 46elks API can post a response towards
  2. Receive a phone call and play an audio file that contains a menu of two options:
    • (1) Find out more about Voice
    • (2) Find out more about SMS
  3. Based on whether the caller presses 1 or 2 play the associated audio file

What you will need for this tutorial

  1. A 46elks Account
  2. A 46elks virtual phone number
  3. A local server - in this guide, we will use ngrok as a tunnel to our local server.
    Never used one before? Have a peak at this ngrok guide
  4. Some basic understanding of how to use the command line
  5. There are some sound files hosted on 46elks.com which you are welcome to use for testing.

Setting up Flask

For a more comprehensive guide to setting up your first Flask project, we recommend following this tutorial Flask by Example – Project Setup.

If your still with us here, then follow these steps. This example uses python3.

The Python code

Open up your favorite editor and add the example code below to your file app.py


      

Configuring Flask endpoints

In the first section of code you will see this line of code:


      

The "next" parameter is a url that 46elks will post towards with the details of which buttons are pressed. The "next" parameter should be used anytime you want to continue the call. To put it a different way, anytime you offer callers an option of which you would like to know the outcome, you should provide a "next" url.

In this case our Flask application will be running on an NGROK server and the location where we would like to receive information is at "/ivr" where we have the next set of instructions.

Configuring your 46elks virtual phone number

We need to configure our 46elks virtual phone number so that our flask app is triggered whenever we receive a phone call. To do this head to your dashboard. In this example we are using NGROK, so we have added details of our NGROK server with /incomingCalls on the end.

Where to get your voice enabled virtual number in your account dashboard

Now we are ready to test our app

You should now be able to test your application ☎️

  1. Initiate your server or NGROK tunnel if you have not already.
  2. Initiate app.py to start your flask application
  3. Call your 46elks number to test

What success looks like

Below are two images. The first shows the terminal running the app.py server and the second is the NGROK server.

The terminal print out of the IVR call data

You can see in the image the different types of data that 46elks posts towards each Flask endpoint and how that data changes. In the example the caller selects the first option by pressing "1" and this is the result we obtain from the the API.

The terminal print out of the IVR call data

You can see in this image the two posts 46elks has made to the two Flask endpoints that we setup in our code example.

Need some more help or have some suggestions?

We would love to hear what you have to say. You can send us an email to help@46elks.com or call us at +46766861004.