Created
December 8, 2022 11:29
-
-
Save miftahafina/69784738b697d566e6d5afd0c2f3e87f to your computer and use it in GitHub Desktop.
Mengambil Data dari Google Sheets Melalui WhatsApp - Full Tutorial https://youtu.be/WPNbvc6lj3U
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cekNilai(nis) { | |
// Buka sheet | |
let sheetUrl = "URL_GOOGLE_SHEETS"; | |
let file = SpreadsheetApp.openByUrl(sheetUrl); | |
let sheet = file.getSheetByName("Sheet1"); | |
let last_row = sheet.getLastRow(); | |
// Ambil data | |
let nilai_list = sheet.getRange(`A2:C${last_row}`).getValues(); | |
let nilai_filtered = nilai_list.filter(el => el[0] == nis); | |
let nama; | |
let nilai; | |
let pesan; | |
if (nilai_filtered.length) { | |
nama = nilai_filtered[0][1]; | |
nilai = nilai_filtered[0][2]; | |
pesan = `Nilai siswa atas nama ${nama} dengan NIS ${nis} adalah ${nilai}.`; | |
} else { | |
pesan = `Nilai untuk siswa dengan NIS ${nis} tidak ditemukan.`; | |
} | |
return pesan; | |
} | |
function doPost(e) { | |
// Membaca pesan | |
let contents = JSON.parse(e['postData']['contents']); | |
let senderMessage = contents['senderMessage']; | |
// Mengurai isi pesan | |
let splittedMessage = senderMessage.split(' '); | |
let nis = splittedMessage[1]; | |
// Memanggil fungsi cekNilai() | |
let pesan = cekNilai(nis); | |
// Mengirim pesan balasan | |
let response = { | |
data: [ | |
{ | |
message: pesan | |
} | |
] | |
} | |
return ContentService.createTextOutput(JSON.stringify(response)); | |
} | |
function test() { | |
Logger.log(cekNilai("230003")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maaf, kalau menggunakan spasi tidak bisa yach ? atau ada code lain ?
contoh nis 2801 78
terima kasih