Use Twilio to provide your user with multiple options through phone calls, so they can be assisted by an agent specialized in the chosen topic. This is basically a call center created with the Task Router API of Twilio. This example uses a PostgreSQL database to log phone calls which were not assisted.
- Python [3.6+] installed in your operative system.
- A Twilio account with a verified phone number. (Get a free account here.) If you are using a Twilio Trial Account, you can learn all about it here.
-
First clone this repository and
cd
into it.$ git clone git@github.com:TwilioDevEd/task-router-django.git $ cd task-router-django
-
Create a new virtual environment.
-
If using vanilla with Python 3 virtualenv:
python -m venv venv source venv/bin/activate
-
If using virtualenvwrapper:
mkvirtualenv task-router-django
-
-
Copy the
.env_example
file to.env
, and edit it to include your Twilio API credentials -
Install the required dependencies, contained in
requirements.txt
.$ pip install -r requirements.txt
-
Setup your database:
createdb task_router
-
Run the migrations.
python manage.py migrate
-
Make sure the tests succeed.
$ python manage.py test --settings=twilio_sample_project.settings.test
-
Start the server.
$ python manage.py runserver
-
Expose your local web server to the internet using ngrok.
You can click here for more details. This step is important because the application won't work as expected if you run it using
localhost
.$ ngrok http 8000
Once ngrok is running open up your browser and go to your ngrok URL. It will look something like this:
http://<sub-domain>.ngrok.io/
-
Configure Twilio to call your webhooks.
You will also need to configure Twilio to call your application via POST when phone calls are received on your Twilio Number. The configuration of Voice should look something like this:
http://<sub-domain>.ngrok.io/call/incoming/
Note: To enable debug logs in local environment, set the DEBUG
variable to True
in the local.py
file
Follow previous guide and in step 3 do:
- Copy the
.env.production.example
file to.env
and add yourDJANGO_SECRET_KEY
-
First make sure you have exported all the required environment variables from the
.env.example
file. Bob and Alice's number should be two different numbers where you can receive calls and SMSs. -
When you run the app, a new workspace will be configured. Once that is done, you are ready to call your Twilio Number where you'll be asked to select a product using your key pad.
-
Select an option and the phone assigned to the product you selected (Bob or Alice's) will start ringing. You can answer the call and have a conversation.
-
Alternatively, if you don't answer the call within 15 seconds, the call should be redirected to the next worker. If the call isn't answered by the second worker, you should be redirected to voice mail and leave a message. The transcription of that message should be sent to the email you specified in your environment variables.
-
Each time a worker misses a call, their activity is changed to offline. Right after they should receive a notification, via SMS, saying that they missed the call. In order to go back online they can reply with
On
. They can as well reply withOff
in order to go back to offline status. -
If both workers' activity changes to
Offline
and you call your Twilio Number again, you should be redirected to voice mail after a few seconds as the workflow timeouts when there are no available workers. Change your workers status with theOn
SMS command to be able to receive calls again. -
Navigate to
https://<ngrok_subdomain>.ngrok.io
to see a list of the missed calls.
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.