This guide shows how to receive and automatically respond to incoming MMS messages on a Plivo number, as you might want to do for someone who’s out of the office or who leaves the company.
Here’s how to use Plivo’s SMS APIs to build this use case.
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. To receive incoming messages you must have a Plivo phone number that supports MMS; you can rent numbers from the Numbers page of the Plivo console or by using the Numbers API. If this is your first time using Plivo APIs, follow our instructions to set up a Python development environment and a web server and safely expose that server to the internet.
Create a Flask server to receive MMS messages
Create a file called receive_mms.py and paste into it this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 from flask import Flask, request import plivo app = Flask(__name__) @app.route("/receive-mms/", methods=["GET", "POST"]) def receive_mms(): # Receive MMS from_number = request.values.get("From") to_number = request.values.get("To") text = request.values.get("Text") media_url = request.values.get("Media0") print("MMS message received - From: %s, To: %s, Text: %s, Media: %s"% (from_number, to_number, text, media_url)) if text.lower() == "hi": text = "Hello!!" media = ["https://media.giphy.com/media/888R35MJTmDxQfRzfS/giphy.gif"] elif text.lower() == "bye": text = "Bye and have a nice day!" media = ["https://media.giphy.com/media/QM5lHSyFjz1XW/giphy.gif"] else: text = "I am glad that we connected" media = ["https://media.giphy.com/media/888R35MJTmDxQfRzfS/giphy.gif"] # Reply recipient using Send MMS API client = plivo.RestClient("<auth_id>", "<auth_token>") response = client.messages.create( src=to_number, dst=from_number, text=text, media_urls=media, type_="mms" ) print(response) return "MMS responded", 200 if __name__ == "__main__": app.run(host="0.0.0.0")
Replace the auth placeholders with your authentication credentials from the Plivo console
Save the file and run it.
$ python receive_mms.py
You should see your basic server application in action at http://localhost:5000/receive-mms/.
Create a Plivo application
Give your application a name — we called our Receive-MMS. Enter the server URL you want to use (for example https://
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application. From the Application Type drop-down, select XML Application. From the Plivo Application drop-down, select Respond-MMS (the name we gave the application).
Click Update Number to save.
Send a text message to the Plivo number you specified using any phone. The message should be replied to the destination number you specified.
Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.