X

Presensi hanya isi NIS, google form dan kirim WhatsApp ke ortu

Presensi hanya isi NIS, google form dan kirim WhatsApp ke ortu

Contoh form

Contoh inputan form di google sheet

Sheet data siswa

Sheet data presensi

Script di apppscript

Ganti Device id, nama sheet data siswa dan data presensi disesuaikan

function presensi(event) {
var APIKey = "xxx";
var NIS = event.namedValues["NIS"][0];
var jenisPresensi = event.namedValues["Presensi"][0];

var searchstudent = searchbynis(NIS);
var Nama = searchstudent[1];
//var NIS2 = searchstudent[2];
var Kelas = searchstudent[3];
var Phone = searchstudent[5];
var Ortu = searchstudent[6];

var sheetName = "DATA PRESENSI"; 
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
var currentTime = new Date();
var tanggalPresensi = Utilities.formatDate(currentTime, Session.getScriptTimeZone(), "dd-MM-yyyy");
var jamPresensi = Utilities.formatDate(currentTime, Session.getScriptTimeZone(), "HH:mm");
var batasWaktu = new Date();
batasWaktu.setHours(10, 0, 0); // Jam 7:00 pagi
var status = currentTime > batasWaktu ? "Terlambat" : "Tepat Waktu";
sheet.appendRow([Nama, NIS, Kelas, tanggalPresensi, jamPresensi, status, jenisPresensi]);

var url = "https://app.whacenter.com/api/send"; 
var pesan   = 
`Yth. Bapak / Ibu orang tua / wali murid ${Ortu}, 

Nama : *${Nama}* 
Kelas : ${Kelas}
telah dicatat hadir pada presensi ${jenisPresensi}
Tanggal : ${tanggalPresensi} 
Jam : ${jamPresensi} WIB
Status : ${status}

_*Terima kasih*_
` ;
const payload = {
   message : pesan,
   number : Phone,
   device_id : APIKey
}

var option = {
    "method": "post",
    "headers" : {
    "content-type" : "application/json"
       },
        "payload" : JSON.stringify(payload)
        };

    var response = UrlFetchApp.fetch(url, option);
       Logger.log(response.getContentText());
        Logger.log(Phone);
        }           
           
function searchbynis(nis){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DATA SISWA")
  var data = sheet.getDataRange().getValues()
  var filterData = data.filter(function(keyword){
    if(keyword[2] == nis){
      return keyword
    }
  })
  
  if(filterData.length>0){
  return filterData[0]
  }
 
 }
adikiss: i'm just an ordinary person | Direktur PT. Adya Global Media | Telegram : <a href="https://t.me/adikiss">t.me/adikiss</a> | Whatsapp : <a href="https://wa.me/6285640206067">wa.me/6285640206067</a> | Facebook : <a href="https://fb.me/adikiswanto">fb.me/adikiswanto</a>
Related Post
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings