Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oimtrust/088ebdb1e8e159cc154170a4802f7eea to your computer and use it in GitHub Desktop.
Save oimtrust/088ebdb1e8e159cc154170a4802f7eea to your computer and use it in GitHub Desktop.
function onFormSubmit(e) {
// Debug log
console.log("Event Object:", e);
if (!e || !e.response) {
console.error("Error: e.response is undefined.");
return;
}
// take email and answer from rensponse
const formResponse = e.response;
const email = formResponse.getRespondentEmail() || "Email Tidak Ditemukan"; // if form collect email
const itemResponses = formResponse.getItemResponses(); // all answer
const name = itemResponses[0] ? itemResponses[0].getResponse() : "Name is empty";
const squad = itemResponses[1] ? itemResponses[1].getResponse() : "Squad is not found";
const testlink = itemResponses[2] ? itemResponses[2].getResponse() : "Test link is empty";
// URL Webhook
const url = "https://chat.googleapis.com/v1/spaces/AAAAfdAo9ck/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=abcdefg";
// Message Format
const message = `*Email Address*: ${email}\n` +
`*Name* : ${name}\n`+
`*Squad* : ${squad}\n\n\n`+
`*Test Link* : ${testlink}\n\n\n`+
'Please check the test cases to be reviewed'
;
const payload = { "text": message };
const options = {
"method": "post",
"headers": { "Content-Type": "application/json; charset=UTF-8" },
"payload": JSON.stringify(payload)
};
// sent to Google Chat
UrlFetchApp.fetch(url, options);
console.log("Message sent to Google Chat:", message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment