Delivery reports serve as your callback service, informing you of the status of messages sent to a specific destination (outbound message) or received on your Plivo number (inbound message).
When a call to the Message API to send a message completes successfully, your message is put into a queue to be sent to its destination. By default, you do not receive an automatic notification regarding the delivery of your message. To get notified about the status of your message, include the url parameter in your API request. This generates a notification when your message reaches its destination, or if it fails to deliver. Your delivery report will show the status — “queued”
, “sent”,
“delivered”
, “undelivered”
or “failed”
— for each recipient, along with other parameters.
You can find SMS delivery reports by visiting Messaging > Logs on the Plivo console.
Similarly, if you want a delivery report when you receive an SMS message on your Plivo number, update the Message URL of the application associated with your Plivo number. Your delivery report will show the status — “delivered” or “undelivered” — along with incoming message details.
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 SMS; 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 Node.js development environment and a web server and safely expose that server to the internet.
Here’s how the process works for inbound messages.
Create a file called report.js and paste into it this code to create a delivery report entry for an inbound message.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var express = require('express');
var bodyParser = require('body-parser');
var app = 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) {
let from_number = request.body.From || request.query.From;
let to_number = request.body.To || request.query.To;
let status = request.body.Text || request.query.Text;
console.log('Message received - From: ' + from_number + ', To: ' + to_number + ', Text: ' + Text+ ');
response.status(200).send("Report received")
});
app.listen(app.get('port'), function () {
console.log('Node app is running on port', app.get('port'));
});
Was this code helpful
Expose your local server to the internet.
Associate the code you created with Plivo by creating a Plivo application. Visiting Messaging > Applications and click Add New Application. You can also use Plivo’s Application API.
Give your application a name — we called ours Delivery Reports. Enter the server URL you want to use (for example https://<yourdomain>.com/delivery_report/) in the Message URL field and set the method to POST. Click Create Application to save 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 Receive SMS (the name we gave the application). Click Update Number to save.
Send an SMS message to your Plivo number using a regular mobile phone. Plivo will send a request to your Message URL with the parameters listed in the Messaging documentation.
You can view the details posted by Plivo by looking at your terminal.
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 SMS; 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 Node.js development environment and a web server and safely expose that server to the internet.
Here’s how the process works for outbound messages.
Create a file called report.js and paste into it this code to create a delivery report entry for an outbound message.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var express = require('express');
var bodyParser = require('body-parser');
var app = 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) {
let from_number = request.body.From || request.query.From;
let to_number = request.body.To || request.query.To;
let status = request.body.Status || request.query.Status;
console.log('Message received - From: ' + from_number + ', To: ' + to_number + ', Status: ' + status+ ');
response.status(200).send("Report received")
});
app.listen(app.get('port'), function () {
console.log('Node app is running on port', app.get('port'));
});
Was this code helpful
Expose your local server to the internet.
To test delivery reports on outbound messages, send an SMS message to a mobile phone using this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var plivo = require('plivo');
(function main() {
'use strict';
var client = new plivo.Client("<auth_id>", "<auth_token>");
client.messages.create(
{
src: "<sender_id>",
dst: "<destination_number>",
text: "Hello, this is a sample text from Plivo",
url: "https://<ngrok_url>/delivery_report/"
}
).then(function (response) {
console.log(response);
});
})();
Was this code helpful
Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234) and url with the ngrok-generated URL.
Plivo will send a request to your url with the parameters listed in the Messaging documentation.
You can view the details posted by Plivo by looking at your terminal.