Created
May 2, 2016 09:47
-
-
Save mugifly/bf703e76aef42866321ae5fe6563dd02 to your computer and use it in GitHub Desktop.
Script for Google Forms - Post to Slack (Thanks for http://chezou.hatenablog.com/entry/2015/03/04/003131)
This file contains hidden or 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
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