Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neno-tech/141e54d71a8f27bc866ac7c861aad294 to your computer and use it in GitHub Desktop.
Save neno-tech/141e54d71a8f27bc866ac7c861aad294 to your computer and use it in GitHub Desktop.
function myFunction() {
var ss =SpreadsheetApp.getActiveSpreadsheet().getSheetByName('เช็คชื่อเข้าเรียน')
var names = ss.getRange(1, 2,1,ss.getLastColumn()).getValues()[0]
var check = ss.getRange(ss.getLastRow(), 2,1,ss.getLastColumn()).getDisplayValues()[0]
var date = Utilities.formatDate(new Date(), 'GMT+7', 'dd/MM/');
var thaiyear = Number(Utilities.formatDate(new Date(), "GMT+7", "yyyy"))+543;
var index =1;
var count = check.filter(col=> col == "ขาด" || col == "ลา").length
var result = "";
check.forEach((r,i)=>{
if(r == "ขาด" || r == "ลา"){
result += '\n'+(index++)+". "+names[i] +": "+ r }
})
var msg="วันที่ "+date+thaiyear+"\n มีนักเรียนไม่มาเรียนจำนวน "+count+" คน ได้แก่"+ result
sendNotify(msg)
}
//ส่งไลน์แจ้งเตือน
function sendNotify(msg){
let payloadJson = {
"message": msg
};
let token = ["7zvnPWh6SROxMUbvl37MIo89B7FYmH2HEt6wpRIgh3h"]; //ใส่ token
let options = {
"method": "post",
"payload": payloadJson,
"headers": {
"Authorization": "Bearer " + token
}
};
UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment