Skip to content

Instantly share code, notes, and snippets.

@fumihumi
Created February 18, 2020 04:22
Show Gist options
  • Save fumihumi/50c214d2aeb6a39f4aec1194f39cf66a to your computer and use it in GitHub Desktop.
Save fumihumi/50c214d2aeb6a39f4aec1194f39cf66a to your computer and use it in GitHub Desktop.
Post slack when submitting Google Forms, If so, set configuration variables. And set a script trigger
const SLACK_WEBHOOK_URL = YOUR_SLACK_WEBOOK_URL;
const CHANNEL = "#xxxx";
const USER_NAME = "bot name";
function submitForm(e) {
const itemResponses = e.response.getItemResponses();
const messages = [];
for (let item of itemResponses) {
const question = item.getItem().getTitle();
const answer = item.getResponse();
messages.push(question + ": " + answer + "\n");
}
sendToSlack(messages.join(""));
}
function sendToSlack(text) {
const data = {
channel: CHANNEL,
username: USER_NAME,
text,
icon_emoji: ":sneezing_face: "
};
const options = {
method: "POST",
contentType: "application/json",
payload: JSON.stringify(data)
};
UrlFetchApp.fetch(SLACK_WEBHOOK_URL, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment