Company
Date Published
Author
Sam Agnew
Word count
867
Language
English
Hacker News points
None

Summary

To programmatically download an image from an MMS message sent to a Twilio number using Python and Flask, one needs to have the Twilio Python helper library installed, as well as the Flask framework. A globally accessible URL is required for Twilio to send a webhook request when a message is received, which can be achieved by using ngrok to open a tunnel to a local machine. The code consists of a Flask app object with one route that responds to incoming messages with a simple text message and downloads an image if present, saving it to a specified directory. Twilio expects an HTTP response in the form of TwiML, which is generated by the Flask app's response. To test this setup, one needs to create a Twilio account, buy a phone number, navigate to the code directory, install dependencies, copy and paste the provided code into a file called `app.py`, replace the `DOWNLOAD_DIRECTORY` variable with the desired path, and point the phone number at the app's URL.