Skip to content

Instantly share code, notes, and snippets.

@miftahafina
Last active August 7, 2023 06:28
Show Gist options
  • Save miftahafina/5f5e21edf7798b48f03df2d1c850df55 to your computer and use it in GitHub Desktop.
Save miftahafina/5f5e21edf7798b48f03df2d1c850df55 to your computer and use it in GitHub Desktop.
Integrasi WhatsApp dengan Google Forms dan Google Sheets - Full tutorial: https://www.youtube.com/watch?v=fZ1-seZFrSc
function SendMessage(nomor_wa, pesan)
{
var url = 'https://pati.wablas.com/api/v2/send-message';
var token = 'YOUR_SECURITY_TOKEN_HERE';
var headers = {
'Authorization' : token,
'content-type' : 'application/json',
};
var payload = JSON.stringify(
{'data':
[{
'phone' : nomor_wa,
'message' : pesan,
'secret' : false,
'retry' : false,
'isGroup' : false
}]
});
var option = {
'method' : 'POST',
'headers' : headers,
'payload' : payload
};
var response = UrlFetchApp.fetch(url,option);
var json = JSON.parse(response.getContentText());
Logger.log(json);
Logger.log(nomor_wa);
}
function ConfirmationResponse(event)
{
var nama = event.namedValues['Nama'][0];
var nomor_wa = event.namedValues['Nomor WA'][0].replace('+', '');
nomor_wa.charAt(0) == '0' ? nomor_wa.replace('0', '62') : nomor_wa;
var pesan = `Terima kasih, ${nama}.
Konfirmasi pembayaran telah diterima, dan menunggu untuk diverifikasi.`;
SendMessage(nomor_wa, pesan);
}
function VerificationResponse(event)
{
var sheet = event.source.getSheets()[0];
var row = event.range.getRow();
var status_verifikasi = sheet.getRange('E' + row).getValue().toUpperCase();
if((event.value.toUpperCase() == 'OK' && status_verifikasi == 'OK') || (event.value.toUpperCase() == 'FAILED' && status_verifikasi == 'FAILED'))
{
var nama = sheet.getRange('B' + row).getValue();
var nomor_wa = sheet.getRange('C' + row).getValue();
pesan = '';
if (status_verifikasi == 'OK') {
pesan = `Alhamdulillah, transfer dari ${nama} berhasil diverifikasi.`;
} else {
pesan = `Maaf, ${nama}. Transfer gagal diverifikasi.`;
}
SendMessage(nomor_wa, pesan);
}
}
@farid-lutfianto
Copy link

Terimakasih

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment