AppScript ส่ง Line Notify พร้อมรูปภาพ

 

นี่คือ Appscript ที่ใช้ส่ง Line จาก application ที่สร้างด้วย AppSheet 

ขอบคุณที่มา : https://www.youtube.com/watch?v=l2YabfjrmhA

.............................................................................................................................................................

function getImgURL(path) {

  let arrpath = path.split("/");

  let foldername = arrpath[0];

  let filename = arrpath[1];

  let fileId = DriveApp.getFoldersByName(foldername).next().getFilesByName(filename).next().getId();

  let fileURL = "https://drive.google.com/uc?id=" + fileId;

  return fileURL;

}


function lineNoti(msg, img) {

  let token = "Line token ของคุณ";


  let formData = {

    'message': msg,

    'imageThumbnail': img,

    'imageFullsize': img

  };


  let options = {

    "method": "post",

    "payload": formData,

    "headers": { "Authorization": "Bearer " + token }

  }


  UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);

}


function alert(content, Image) {

  let bfURL = getImgURL(Image);

  //Logger.log(bfURL);

  lineNoti(content, bfURL);

}

....................................................................................................................................................................


Previous
Next Post »