When you make a Send Message API request to Plivo, the message is first added to our message processing queue. It is then dequeued and sent out to our telecom carriers for delivery. The message then traverses through global networks and is finally delivered to the intended destination number.
The message_state attribute of the Message Detail Record (MDR) reflects the current status of the message.
In this guide, we will see how to receive message status updates in real-time using callback URLs. A callback URL is a web-service endpoint which, when provided in the Send Message API request, is invoked whenever the status of the message is updated.
Setting up message status tracking is key for monitoring the processing times and delivery rates of your SMS traffic.
Here are the steps we need to follow to start receiving message status updates.
You must have a live web server to receive message status updates from Plivo.
Let’s assume your web server is located at
Create a new service endpoint exclusively to receive incoming messages from Plivo. For example:
The sample code below is for a service endpoint that accepts the incoming request from Plivo, parses the request body, and prints the message_uuid,
messate_state and other relevant information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import plivo, plivoxml from flask import Flask, request app = Flask(__name__) @app.route("/delivery_report/", methods=['GET','POST']) def report(): # Sender's phone number from_number = request.values.get('From') # Receiver's phone number - Plivo number to_number = request.values.get('To') # Status of the message status = request.values.get('Status') # Message UUID uuid = request.values.get('MessageUUID') # Prints the status of the message print "From: %s, To: %s, Status: %s, MessageUUID: %s" % (from_number, to_number, status, uuid) return "Delivery status reported" if __name__ == '__main__': app.run(host='0.0.0.0', debug=True)
Read our API reference to learn more about the attributes that are sent across to the status update url.
url parameter in the Send Message API request to the web service endpoint created in the previous step. Plivo will then invoke this url whenever the status of the message changes.