Created
February 18, 2020 04:22
-
-
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
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
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