Use Twilio to receive SMS and MMS messages. For a step-by-step tutorial see the Twilio docs.
Twilio supports HTTP Basic and Digest Authentication. Authentication allows you to password protect your TwiML URLs on your web server so that only you and Twilio can access them.
Learn more about HTTP authentication here, which includes sample code you can use to secure your web application by validating incoming Twilio requests.
This project is built using the Django web framework. It runs on Python 2.7+ and Python 3.4+.
To run the app locally:
-
Clone this repository and
cd
into itgit clone git@github.com:TwilioDevEd/receive-mms-django.git cd receive-mms-django
-
Create a new virtual environment using virtualenv
virtualenv -p python3 venv source venv/bin/activate
-
Install the requirements
pip install -r requirements.txt
-
Copy the sample configuration file and edit it to match your configuration
cp .env.example .env
You can find your
TWILIO_ACCOUNT_SID
andTWILIO_AUTH_TOKEN
in your Twilio Account Settings. You will also need aTWILIO_PHONE_NUMBER
, which you may find here.Note: To run using production environment use
cp .env.production.example .env
and follow previous steps -
Load your environment configurations into your shell session
source .env
-
Run the migrations
python manage.py migrate
-
Run the application
python manage.py runserver
-
Expose your application to the wider internet using ngrok. This step is important because the application won't work as expected if you run it through localhost.
ngrok http -host-header=localhost 8000
Once ngrok is running, open up your browser and go to your ngrok URL. It will look something like this:
http://9a159ccf.ngrok.io
Note: You can read this blog post for more details on how to use ngrok.
-
Configure Twilio to call your webhooks
You will also need to configure Twilio to call your application when calls are received on your TWILIO_NUMBER. The MMS url should look something like this:
http://6b5f6b6d.ngrok.io/incoming/
- Check it out at http://localhost:8000
That's it
Note: To enable debug logs in local environment, set the DEBUG
variable to True
in the developemt.py
file
-
Send an MMS to your twilio number
-
Access http://localhost:8000. You should see a list with all the resources sent through your MMS
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.