Send WhatsApp Messages from Google Sheets using Google Apps Script

This post shows you How to Send WhatsApp Messages from Google Sheets with Google Apps Script.

I am using APIWHA service to send WhatsApp messages. we will need to register with the APIWHA. Instructions are available on the official site.

Send WhatsApp Messages from Google Sheets with Google Apps Script, do this:

Send WhatsApp Messages from Google Sheets

Send WhatsApp Messages from Google Sheets using Google Apps Script

In sheet where we add manually contact details and Message. column C is senders Whatsapp mobile number

  • We can add multiple rows means multiple messages in google sheet
  • We must have to add the mobile no (Column C) and message (Column E)

Apps Script: Send WhatsApp Messages from Google Sheets

function onOpen( ){
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Menu')
      .addItem('Send Whatsapp Message', 'myFunction')
      .addSeparator()
      .addToUi();
}
function myFunction() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process - 2 exempts my header row
  var numRows = sheet.getLastRow();   // Number of rows to process
  var numColumns = sheet.getLastColumn();
  var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns); 
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var fName =     row[0]; 
    var lName =     row[1];  
    var mobileNo =  row[2]; 
    var mess =      row[4];
    Logger.log(mess);   
    var my_apikey = "APIKEY";
    var destination = mobileNo; 
    var message = mess; 
    var api_url = "http://panel.apiwha.com/send_message.php"; 
    api_url += "?apikey="+ my_apikey; 
    api_url += "&number="+ destination; 
    api_url += "&text="+ encodeURIComponent (message); 
    var response = UrlFetchApp.fetch(api_url);
    Logger.log(response.getContentText());   
  }
}

In sheet menu, tools > script editor. The script editor will open Paste the code below in script editor. After pasting the code please refresh the sheet.
You will see the custom menu, run that menu than authorize the code and after authorization Whatsapp message will be sent