Lompat ke konten
View Categories

Kirim broadcast pesan whatsapp tiap penerima pesan berbeda file / gambar

Kirim broadcast pesan whatsapp tiap penerima pesan berbeda file / gambar dari google spreadsheet

video

appscript

function sendWhatsAppMessages() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var dataRange = sheet.getDataRange();
  var data = dataRange.getValues();
   var startrow = sheet.getRange("C8").getValue(); // ganti sesuai letak cell awal bc
  var endrow = sheet.getRange("C9").getValue(); // ganti sesuai letak cell akhir bc

  
  for (var i = startrow; i <= endrow; i++) {
    var row = data[i];
    var name = row[1];
    var phoneNumber = row[2]; // Kolom nomor telepon
    var message = row[3]; // Kolom pesan
    var file = row[4]; // Kolom link file
    
    sendWaFile(phoneNumber, message, file); // jika file berupa pdf ada 2 kali fungsi kirim file dan text 
    sendWaText(phoneNumber, message); // jika file berupa gambar fungsi ini sebaiknya tidak dipakai
  }
}

function sendWaFile(number, message, file) {
  var idDevice = "xxx"; // Ganti dengan ID perangkat Anda
  // var date = new Date(); 
  // var schedule = Utilities.formatDate(date, Session.getScriptTimeZone(), "yyyy-MM-dd HH:mm:ss"); 
  
  var formdata = {
    "device_id" : "" + idDevice,
    "number" : "" + number,
    "message" : "" + message,
    "file" : "" + file,
    // "schedule" : "" + schedule
  };

  var requestOptions = {
    method: 'POST',
    contentType: 'application/json',
    payload: JSON.stringify(formdata),
    redirect: 'follow'
  };

  var response = UrlFetchApp.fetch("https://app.whacenter.com/api/send", requestOptions);
  Logger.log(response);
}

function sendWaText(number, message) {
  var idDevice = "xxx"; // Ganti dengan ID perangkat Anda
  // var date = new Date();
  // var schedule = Utilities.formatDate(date, Session.getScriptTimeZone(), "yyyy-MM-dd HH:mm:ss");
  
  var formdata = {
    "device_id" : "" + idDevice,
    "number" : "" + number,
    "message" : "" + message,
    //"file" : "" + file,
    // "schedule" : "" + schedule
  };

  var requestOptions = {
    method: 'POST',
    contentType: 'application/json',
    payload: JSON.stringify(formdata),
    redirect: 'follow'
  };

  var response = UrlFetchApp.fetch("https://app.whacenter.com/api/send", requestOptions);
  Logger.log(response);
}

Powered by BetterDocs

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *