Learn how to use Twilio Client to conduct automated phone surveys.
This project is built using the Flask web framework. It runs on Python 2.7+ and Python 3.4+.
To run the app locally follow these steps:
-
Clone this repository and
cd
into it. -
Create and activate a new python3 virtual environment.
python3 -m venv venv source venv/bin/activate
-
Install the requirements.
pip install -r requirements.txt
-
Copy the
.env.example
file to.env
, and edit it to match your database. -
Activate Flask development environment
export FLASK_ENV=development
-
Run the migrations.
python manage.py db upgrade
-
Seed the database.
python manage.py dbseed
Seeding will load
survey.json
into SQLite. -
Expose your application to the wider internet using ngrok.
To actually forward incoming calls, your development server will need to be publicly accessible. We recommend using ngrok to solve this problem.
ngrok http 5000
Once you have started ngrok, update your TwiML app's voice URL setting to use your ngrok hostname. It will look something like this:
http://88b37ada.ngrok.io/voice
-
Start the development server.
python manage.py runserver
Once ngrok is running, open up your browser and go to your ngrok URL. It will
look like this: http://88b37ada.ngrok.io
That's it!
You will also need to configure Twilio to call your application when calls are received
You will need to provision at least one Twilio number with voice capabilities so the application's users can take surveys. You can buy a number right here. Once you have a number you need to configure your number to work with your application. Open the number management page and open a number's configuration by clicking on it.
The URL you will place the the Request URL field will be as follows. Set the HTTP method to GET. Be sure to change the ngrok hostname to your own.
http://20ee7404.ngrok.io/voice
Similarly, you must configure the SMS messaging section of your Twilio Phone Number
To call the /message
webhook.
http://20ee7404.ngrok.io/voice
See the images below for an example:
You can then visit the application at http://localhost:5000/.
Mind the trailing slash.
You can run the tests locally through coverage:
-
Run the tests.
python manage.py test
You can then view the results with coverage report
or build an HTML report with coverage html
.
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.