Once the Message API request is successful, your SMS will be put into a queue to be sent to its destination. By default, you will not receive an automatic notification regarding the delivery of your SMS. To get notified on the status of your message, include the url parameter in your API request. You can also find your SMS delivery reports in the SMS Logs of your Plivo account. This will automatically output a notification when your SMS reaches its destination, or if it fails to deliver. Your delivery report will update to show either "queued", "sent", "delivered", "undelivered", or "failed" for each individual recipient.
Note: Long SMS messages are automatically split and concatenated into a seamless user experience. When checking Message Logs and Delivery Reports for long SMS messages that are split, look for the `ParentMessageUUID`, which is the same in all split messages and identical to the UUID of the first message in the split sequence of messages.
Advanced Hack: Check out our Message API docs to see how you can get the details of a single message or all your messages in a single `GET` request.
Note: A phone number is required only for sending SMS to US and Canadian phone numbers. However, country-specific carrier conditions may still apply. You can buy a US or Canadian phone number through the Buy Numbers tab on your Plivo account UI.
Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.
Note: If you are using a Plivo Trial account for this example, you can only send sms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.
Set up a Web Server
Let’s assume your web server is located at http://example.com. Below is a snippet to set up a route on your webserver. Now when we send an HTTP request to http://example.com/delivery_report/ this route will be invoked. This route will be the 'url' parameter when sending an sms using the Message API.
Note: For PHP, the route will be example.com/delivery_report.php.
Copy the relevant code below into a text file and save it. Let’s call it, 'delivery_report'.
Customize the delivery report to include the parameters you need.
fromflaskimportFlask,request,make_response,Responseapp=Flask(__name__)@app.route('/delivery_report/',methods=['GET','POST'])definbound_sms():# Sender's phone number
from_number=request.values.get('From')# Receiver's phone number - Plivo number
to_number=request.values.get('To')# The text which was received
text=request.values.get('Text')# Message UUID
uuid=request.values.get('MessageUUID')# Print the message
print('Message received - From: %s, To: %s, Text: %s, MessageUUID: %s'%(from_number,to_number,text,uuid))return"Delivery status reported"if__name__=='__main__':app.run(host='0.0.0.0',debug=True)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
require"sinatra"post"/delivery_report/"do# Sender's phone numberfrom_number=params[:From]# Receiver's phone number - Plivo numberto_number=params[:To]# The text which was receivedtext=params[:Text]# Print the messageputs"Message received - From: #{from_number}, To: #{to_number}, Text: #{text}, MessageUUID: #{uuid}"puts"Delivery status reported"end
varexpress=require('express');varbodyParser=require('body-parser');varapp=express();app.use(bodyParser.urlencoded({extended:true}));app.use(function(req,response,next){response.contentType('application/xml');next();});app.set('port',(process.env.PORT||5000));app.all('/delivery_report/',function(request,response){// Sender's phone numbervarfrom_number=request.body.From||request.query.From;// Receiver's phone number - Plivo numbervarto_number=request.body.To||request.query.To;// The text which was receivedvartext=request.body.Text||request.query.Text;//Message UUIDvaruuid=request.body.MessageUUID||request.query.MessageUUID;//Prints the messageconsole.log('Message received - From: '+from_number+', To: '+to_number+', Text: '+text+', MessageUUID: '+uuid);console.log('Delivery status reported');});app.listen(app.get('port'),function(){console.log('Node app is running on port',app.get('port'));});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?phprequire'vendor/autoload.php';// Sender's phone numer$from_number=$_REQUEST["From"];// Receiver's phone number - Plivo number$to_number=$_REQUEST["To"];// The SMS text message which was received$text=$_REQUEST["Text"];// Message UUID$uuid=$_REQUEST["MessageUUID"];// Prints the messageecho("Message received - From $from_number, To: $to_number, Text: $text, MessageUUID: $uuid");echo("Delivery status reported");?>
importstaticspark.Spark.*;publicclassDelivery{publicstaticvoidmain(String[]args){get("/delivery_sms",(request,response)->{// Sender's phone numberStringfrom_number=request.queryParams("From");// Receiver's phone number - Plivo numberStringto_number=request.queryParams("To");// The text which was receivedStringtext=request.queryParams("Text");// Message UUIDStringuuid=request.queryParams("MessageUUID");response.type("application/xml");// Print the messageSystem.out.println(from_number+" "+to_number+" "+text);return"Message Received";});}}
packagemainimport("net/http""github.com/go-martini/martini")funcmain(){m:=martini.Classic()m.Get("/delivery_report",func(whttp.ResponseWriter,r*http.Request)string{w.Header().Set("Content-Type","application/xml")// Sender's phone numberfromnumber:=r.FormValue("From")// Receiver's phone number - Plivo numbertonumber:=r.FormValue("To")// The text which was receivedtext:=r.FormValue("Text")//Message UUIDuuid:=r.FormValue("MessageUUID")// Print the messageprint("Message Received - ",fromnumber," ",tonumber," ",text," ",uuid)return"Delivery status reported"})m.Run()}
usingNancy;usingSystem;usingSystem.Collections.Generic;namespaceNancyStandalone{publicclassFunctionsModule:NancyModule{publicFunctionsModule(){Post("/delivery",parameters=>{// Sender's phone numberStringfrom_number=Request.Form["From"];// Receiver's phone numberStringto_number=Request.Form["To"];// The text which was receivedStringtext=Request.Form["Text"];// Print the messageConsole.WriteLine("Message received - From: {0}, To: {1}, Text: {2}",from_number,to_number,text);return"Delivery status reported";};}}}
Sample Output
From: 1111111111, To: 3333333333, Status: delivered, MessageUUID: 0936ec98-7c4c-11e4-9bd8-22000afa12b9
SMS Delivery and Notifications
The following parameters are then sent to the URL:
Parameter
Description
MessageUUID
The unique ID for the message.
To
Phone number of the recipient.
From
The sender ID used as the source address for the message.
Status
Status of the message including “queued”, “sent”, “failed”, “delivered”, “undelivered”, or “rejected”.
Units
Number of units into which a long SMS was split
TotalRate
This is the charge applicable per outbound SMS unit.
TotalAmount
Total charge for sending the SMS (TotalRate * No. of Units)
MCC
Mobile Country Code of the To number. (See here for more details)
MNC
Mobile Network Code of the To number. (See here for more details)
ErrorCode
The Plivo error code which identifies the reason for the message delivery failure. This parameter is only defined for ‘failed’ or ‘undelivered’ messages.
ParentMessageUUID (reserved for future use)
Same as the MessageUUID. This parameter is reserved for future use, and should be ignored for now.
PartInfo (reserved for future use)
This parameter is reserved for future use, and should be ignored for now.
Rate this page
🥳 Thank you! It means a lot to us!
×
Help Us Improve
Thank you so much for rating the page, we would like to get your input for further improvements!