Learn how to use Twilio Client to make browser-to-phone and browser-to-browser calls with ease. The unsatisfied customers of the Birchwood Bicycle Polo Co. need your help!
Full Tutorial: https://www.twilio.com/docs/howto/walkthrough/browser-calls/python/django
This project is configured to use a TwiML App, which allows us to easily set the voice URLs for all Twilio phone numbers we purchase in this app.
Create a new TwiML app at https://www.twilio.com/user/account/apps/add and use its Sid
as the TWIML_APPLICATION_SID
environment variable wherever you run this app.
Once you have created your TwiML app, configure your Twilio phone number to use it (instructions here). If you don't have a Twilio phone number yet, you can purchase a new number in your Twilio Account Dashboard.
This project is built using the Django web framework. It runs on Python 2.7+ and Python 3.4+.
To run the app locally, first clone this repository and cd
into its directory. Then:
-
Create a new virtual environment:
-
If using vanilla virtualenv:
virtualenv venv source venv/bin/activate
-
If using virtualenvwrapper:
mkvirtualenv browser-calls-django
-
-
Install the requirements:
pip install -r requirements.txt
-
Copy the
.env_example
file to.env
, and edit it to include your Twilio API credentials and the phone number and TwimL App Sid you made above -
Run
source .env
to apply the environment variables (or even better, use autoenv) -
Start a local PostgreSQL database and create a database called
browser_calls
:- If on a Mac, we recommend Postgres.app. After install, open psql and run
CREATE DATABASE browser_calls;
- If Postgres is already installed locally, you can just run
createdb browser_calls
from a terminal
- If on a Mac, we recommend Postgres.app. After install, open psql and run
-
Run the migrations with:
python manage.py migrate
-
Be sure to create a superuser so you can access the Support Dashboard and the Django admin:
python manage.py createsuperuser
-
Start the development server:
python manage.py runserver
To actually forward incoming calls, your development server will need to be publicly accessible. We recommend using ngrok to solve this problem.
Once you have started ngrok, update your TwiML app's voice URL setting to use your ngrok hostname, so it will look something like this:
http://88b37ada.ngrok.io/support/call
You can run the tests locally through coverage:
$ coverage run manage.py test --settings=twilio_sample_project.settings.test
You can then view the results with coverage report
or build an HTML report with coverage html
.