This repository shows how to create a simple IVR using Python and Twilio. Make sure to have a Twilio account and a phone number in your account.
The first thing is you need to make sure to install the Twilio library and Flask framework.
- To install Twilio library, please follow this link.
- To install the Flask framework, please use this link.
Save the ivr_test.py script on your computer. From this example, you will notice that you get different replies depending on your answer, see the "if" conditional. You may add the <Dial>
verb in one of the conditionals if you want the call to be routed to another phone number, more info can be found here.
Then, if you are running windows or mac, you need to open the command prompt or the terminal, respectively, and navigate to where you saved the file.
For windows, you need to run the following:
set FLASK_APP=ivr_test.py
flask run
For mac:
export FLASK_APP=ivr_test.py
flask run
Up to this point, you have made your web application available in your localhost. Now, you need to make it public on internet. If you do not have a server available at the moment, I would recommend to check out ngrok. This application allows you to host your web app on the internet for 2 hours (for free accounts) so you can test your application. In this Twilio blog you will be able to see how you can use ngrok and how to configure your webhook on your Twilio console.