Use Twilio to receive WhatsApp media messages. For a step-by-step tutorial see the Twilio docs.
This project is built using the Flask web framework. It runs on Python 3.6+.
To run the app locally:
-
Clone this repository and
cd
into itgit clone [email protected]:TwilioDevEd/whatsapp-media-tutorial-flask.git cd whatsapp-media-tutorial-flask
-
Create a new virtual environment using virtualenv
virtualenv -p python3 venv source venv/bin/activate
-
Install the requirements
pip install -r requirements.txt
-
Run the application
flask run
-
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
Note: You can read this blog post for more details on how to use ngrok.
-
Configure Twilio's Sandbox for WhatsApp to call your webhook URL
You will need to configure your Twilio Sandbox for WhatsApp to call your application (exposed via ngrok) when your Sandbox number receives an incoming message. Your URL will look something like this:
http://6b5f6b6d.ngrok.io/whatsapp/
Here are detailed instructions for Twilio Sandbox for WhatsApp
-
Check it out at http://localhost:5000
-
Send a message with a media attachment to your WhatsApp Sandbox phone number
-
Your Flask application should display the incoming request from Twilio. In a few moments, you should get back a WhatsApp reply featuring a "good boy."
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.