Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neno-tech/e90629180e4273772c4d529d0c07d97c to your computer and use it in GitHub Desktop.
Save neno-tech/e90629180e4273772c4d529d0c07d97c to your computer and use it in GitHub Desktop.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('xxxxx')
var names = ss.getRange(1, 2, 1, ss.getLastColumn()).getValues()[0]
var check = ss.getRange(ss.getLastRow(), 2, 1, ss.getLastColumn()).getValues()[0]
var date = Utilities.formatDate(new Date(), 'GMT+7', 'dd/MM/')//วันที่
var year = 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+year+"\n มีนักเรียนไม่มาเรียนจำนวน "+count+" คน ได้แก่"+result
sendNotify(msg)
}
//ส่งไลน์แจ้งเตือน
function sendNotify(msg){
let payloadJson = {
"message": msg
};
let token = ["xxx"]; //ใส่ 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