Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for Google Forms - Post to Slack (Thanks for http://chezou.hatenablog.com/entry/2015/03/04/003131)
function test () {
postToSlack('Hello!');
}
function postToSlack (text) {
var SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/XXXXX/YYYYY/ZZZZZ';
var SLACK_CHANNEL_NAME = '#general';
var SLACK_USER_NAME = 'Google Forms';
var payload = {
channel: SLACK_CHANNEL_NAME,
username: SLACK_USER_NAME,
text: text
};
UrlFetchApp.fetch(SLACK_WEBHOOK_URL, {
method: 'POST',
contentType: 'application/json',
payload: JSON.stringify(payload)
});
}
function onFormSubmit (e) {
var text = e.source.getTitle() + '\n'
+ e.source.getPublishedUrl() + '\n--------------------\n\n';
var items = e.response.getItemResponses();
for (var j = 0; j < items.length; j++){
var item = items[j];
text += '[' + item.getItem().getTitle() + ']\n';
text += item.getResponse() + '\n\n';
}
postToSlack(text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.