Delivery Reports

    Overview

    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.

    Implementation

    In this section, we will guide you to build an app to Receive Delivery Reports.

    Prerequisites

    • Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo Console. Click here to sign-up for a Plivo account if you haven’t already!

      Find Your Auth Credentials on Plivo Console

    • Plivo Phone Number(Optional): To send messages to the United States and Canada, you must have a Plivo phone number that supports SMS. Numbers can be purchased from the Numbers section of your Plivo Console and use the same as the source number/from number for the outbound SMS. This number will also help you receive incoming SMS as you must have a SMS-enabled Plivo phone number to do the same. Please note that you can also purchase numbers using the Numbers API.

      Buy a New Plivo Number

    Install Node.js and the Plivo Node.js Server SDK

    You must set up and install Node and Plivo’s Node SDK to make your first call. Here’s how.

    Install Node.js

    Operating SystemInstructions
    macOS & LinuxTo see if you already have Node.js installed, run the command node --version in the terminal. If you don't have it installed, you can install it from here .
    WindowsTo install Node.js on Windows you can download it from here and install.

    Install Plivo Node.js Package & Express

    • Create a project directory, run the following command:

      $ mkdir mynodeapp
      
    • Change the directory to our project directory in the command line:

      $ cd mynodeapp
      
    • Install the SDK using npm

      $ npm install plivo
      $ npm install express
      
    • For features in beta, use the beta branch:

      $ npm install plivo@beta
      

    Delivery Reports

    Below is the code to handle delivery reports.

    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
    
    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) {
        // Sender's phone number
        var from_number = request.body.From || request.query.From;
        // Receiver's phone number - Plivo number
        var to_number = request.body.To || request.query.To;
        // The text which was received
        var text = request.body.Text || request.query.Text;
        //Message UUID
        var uuid = request.body.MessageUUID || request.query.MessageUUID;
        //Prints the message
        console.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'));
    });
    

    Exposing your local server to the internet

    To receive Incoming Messages and to handle callbacks, your local server should be able to connect with Plivo API service, Ngrok is a tunneling software used to expose a web server running on your local machine to the internet. Using Ngrok you can set webhooks which can talk to Plivo server.

    ngrok block diagram

    You can download and install ngrok from here. Follow the detailed configuration instructions to get started.

    Run ngrok on the port which currently hosts your application. For example, if your port number is 80, run the following command:

    ./ngrok http <port_on_which_your_local_server_is_running>
    

    This will give you a UI with links that look like ngrok.io/* which you can use to access your local server using the public network.

    Sample ngrok CLI

    Create an Application

    1. Create an Application by visiting the Application Page and click on New Application. You can also use Plivo’s Application API.
    2. Give your application a name. Let’s call it Receive SMS. Enter your server URL (e.g. http://example.com/delivery_reports/) in the Message URL field and set the method as POST. See our Application API docs to learn how to modify your application through our APIs.
    3. Click on Create Application to save your application.

    Create Application

    Assign a Plivo number to your app

    1. Navigate to the Numbers page and select the phone number you want to use for this app.
    2. Select Receive SMS (name of the app) from the Plivo App dropdown list.
    3. Click on Update to save.

    Assign Phone Number to Receive Delivery Reports

    Test and validate

    Send an SMS to your Plivo number using a regular mobile phone. Plivo will send a request to your Message URL with the parameters listed in the Messages Documentation.