Home Product Blogs
If you are using your own msg91 account, then please follow the below process to set up the delivery report webhook. What you are doing here is, creating a web application using Google App Script that can accept POST requests coming from msg91. Need help? contact us at [email protected].
  Open your spreadsheet using to send SMS
  Create a new sheet and name it as 'Webhook'
  Copy the code below
  Open your spreadsheet using to send SMS
  Go to tools > Script Editor
  Paste the code
  Go to File > Manage Version
  In description give 'msg91'
  Click on 'Save new version'
  Go to Publish > Deploy as web app
  In Project version dropdown, select the latest version
  Click on update
  Copy the webapp url
  Go to your msg91 account
  Click on API > Webhook
  Paste the webapp url and click on save
  Done!
function doPost(e) {
    try{
        var data = e.parameter.data;
        data = JSON.parse(data);
        var deliveryReport = [];
        for(var i = 0; i < data.length; i++){ 
            var requestId = data[i]["requestId"];
            var report = data[i]["report"]; 
            for(var j = 0; j < report.length; j++){ 
                var row = []; 
                row.push(report[j]["date"]); 
                row.push(report[j]["number"]);
                row.push(requestId);
                row.push(report[j]["desc"]); 
                deliveryReport.push(row); 
            }
        }
        LockService.getScriptLock().tryLock(1000); 
        var row = SpreadsheetApp.getActiveSpreadsheet()
                    .getSheetByName("Webhook")
                    .getLastRow()+1;
        SpreadsheetApp.getActiveSpreadsheet()
            .getSheetByName("Webhook")
            .getRange(row, 1, deliveryReport.length, 4)
            .setValues(deliveryReport); 
        LockService.getScriptLock().releaseLock(); 
    }
    catch(err){
        SpreadsheetApp.getActiveSpreadsheet()
        .getSheetByName("Webhook")
        .appendRow([JSON.stringify(err)]); 
    }
}