简体   繁体   中英

Send Message to LINE Notify from Google Spreadsheets with Apps Script

So I am trying to send message to LINE Notify from Google Spreadsheets via google form responses, I already testing the API with Postman and it works, I got the Notification, however it doesn't works on the Apps Script Code. here's the error log:

在此处输入图像描述

function autoFillPendataanKontak(e) {
  var nama = e.values[1];
  var nim = e.values[2];
  var bidang = e.values[3];
  
  var file = DriveApp.getFileById('------');
  
  var doc = DocumentApp.openById(file.getId()); 
  
  var body = doc.getBody();

  function sendLineNotify(messageNama, messageBidang) {

    var token = ["------"];
    var options = {
        "method": "post",
        "payload": messageNama + " telah mendaftar di Bidang " + messageBidang,
        "headers": {
            "Authorization": "Bearer " + token
        }
    };
    UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
  }

  function appendTable(variabel1, variabel2){
      var rangePSDI = null;
      var searchElement = body.findElement(DocumentApp.ElementType.TABLE, rangePSDI);
      element = searchElement.getElement();
      table = element.asTable();
      if (bidang == 'PSDI') {
          body.replaceText('{{a}}', variabel1);
          body.replaceText('{{b}}', variabel2);
          var tr = table.appendTableRow();
          var ukur = table.getNumRows();    
          ukur -= 3;
          tr.appendTableCell(ukur+1);
          tr.appendTableCell("{{a}}");
          tr.appendTableCell("{{b}}");
      } else if (bidang == 'PSDM') {
          body.replaceText('{{c}}', variabel1);
          body.replaceText('{{d}}', variabel2);
          var tr = table.appendTableRow();
          var ukur = table.getNumRows();
          ukur -= 3;
          tr.appendTableCell(ukur + 1);
          tr.appendTableCell("{{c}}");
          tr.appendTableCell("{{d}}");
      }
  }

  appendTable(nama, nim);
  sendLineNotify(nama, bidang);

  doc.saveAndClose(); 
}

Solved the problem, I just forgot the "message=" on payload

"payload": "message=" + messageNama + " telah mendaftar di Bidang " + messageBidang,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM