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 a new virtual environment:
-
If using vanilla virtualenv:
virtualenv venv source venv/bin/activate
-
If using virtualenvwrapper:
mkvirtualenv automated-survey
-
-
Install the requirements.
pip install -r requirements.txt
-
Copy the
.env.example
file to.env
, and edit it to match your database. -
Run
source .env
to apply the environment variables (or even better, use autoenv) -
Run the migrations.
python manage.py db upgrade
-
Seed the database.
python manage.py dbseed
Seeding will load
survey.json
into SQLite. -
Expose your appliction 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/support/call
-
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.
Next, edit the "Request URL" field under the "Voice" section and point
it towards your ngrok-exposed application /voice/
route. Set
the HTTP method to GET.
Do the same with the "Messaging" section, but towards the /message
route.
See the images below for an example:
You can then visit the application at http://localhost:8000/.
Mind the trailing slash.
You can run the tests locally through coverage:
-
Run the tests.
$ coverage run 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.