Skip to content

Latest commit

 

History

History
151 lines (101 loc) · 5.36 KB

README.md

File metadata and controls

151 lines (101 loc) · 5.36 KB
Twilio

Task Router - Python/Django

Build and test

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.

Read the full tutorial here

Prerequisites

  1. Python [3.6+] installed in your operative system.
  2. 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.

Local Development

  1. First clone this repository and cd into it.

    $ git clone [email protected]:TwilioDevEd/task-router-django.git
    $ cd task-router-django
    
  2. 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
  3. Copy the .env_example file to .env, and edit it to include your Twilio API credentials

  4. Install the required dependencies, contained in requirements.txt.

    $ pip install -r requirements.txt
  5. Setup your database:

    createdb task_router
  6. Run the migrations.

    python manage.py migrate
  7. Make sure the tests succeed.

    $ python manage.py test --settings=twilio_sample_project.settings.test
  8. Start the server.

    $ python manage.py runserver
  9. 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/

  10. 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/
    

    Configure SMS

Note: To enable debug logs in local environment, set the DEBUG variable to True in the local.py file

Use Production Environment

Follow previous guide and in step 3 do:

  1. Copy the .env.production.example file to .env and add your DJANGO_SECRET_KEY

How to Demo

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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 with Off in order to go back to offline status.

  6. 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 the On SMS command to be able to receive calls again.

  7. Navigate to https://<ngrok_subdomain>.ngrok.io to see a list of the missed calls.

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.