Webhook to listen and download MMS content to files
authorJacob Casper <dev@jacobcasper.com>
Fri, 3 Apr 2020 03:14:13 +0000 (22:14 -0500)
committerJacob Casper <dev@jacobcasper.com>
Fri, 3 Apr 2020 03:14:13 +0000 (22:14 -0500)
.gitignore [new file with mode: 0644]
mms-download.py [new file with mode: 0644]
requirements.txt [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..728cf4e
--- /dev/null
@@ -0,0 +1,4 @@
+bin/
+lib/
+lib64
+pyvenv.cfg
diff --git a/mms-download.py b/mms-download.py
new file mode 100644 (file)
index 0000000..352c861
--- /dev/null
@@ -0,0 +1,21 @@
+import requests
+from flask import Flask, request
+from twilio.twiml.messaging_response import MessagingResponse
+
+app = Flask(__name__)
+
+@app.route("/mms", methods=['POST'])
+def sms_reply():
+    """Respond to incoming multimedia messages with a confirmed download text."""
+    if request.form['NumMedia'] is not None:
+        urls = [request.form['MediaUrl' + str(idx)] for idx in range(int(request.form['NumMedia']))]
+    photos = {url.split("/")[-1]: requests.get(url) for url in urls}
+    for identifier, photo in photos.items():
+        with open(identifier + '.jpg', 'wb') as f:
+            f.write(photo.content)
+    resp = MessagingResponse()
+    resp.message("Upload received!")
+    return str(resp)
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=9092, debug=True)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..827e7e1
--- /dev/null
@@ -0,0 +1,15 @@
+certifi==2019.11.28
+chardet==3.0.4
+Click==7.0
+Flask==1.1.1
+idna==2.8
+itsdangerous==1.1.0
+Jinja2==2.11.0
+MarkupSafe==1.1.1
+PyJWT==1.7.1
+pytz==2019.3
+requests==2.22.0
+six==1.14.0
+twilio==6.35.3
+urllib3==1.25.8
+Werkzeug==0.16.1