Skip to content

Instantly share code, notes, and snippets.

@zackseuberling
Forked from andychase/googleforms2slack.gs
Last active March 22, 2017 01:12
Show Gist options
  • Save zackseuberling/3005309a067b32dde732f58bda763104 to your computer and use it in GitHub Desktop.
Save zackseuberling/3005309a067b32dde732f58bda763104 to your computer and use it in GitHub Desktop.
Google Forms Slack Notification
// Google Forms Slack Notification
// Andy Chase <github.com/andychase>
// License: CC0 1.0 Universal <creativecommons.org/publicdomain/zero/1.0>
// Install 1: This code goes in ( tools > script editor... ) of your google docs form
// Install 2: ( resources > current project triggers ) ( [onSubmit], [from Form], [On form submit] )
// Setup 1: Put your slack api url below
var POST_URL = "https://hooks.slack.com/services/";
function onSubmit(e) {
var responses = e.response.getItemResponses();
var fields = [];
for (var j = 0; j < responses.length; j++) {
var response = responses[j];
var field = {
title: response.getItem().getTitle(),
value: response.getResponse()
};
fields.push(JSON.stringify(field));
}
var payload = { payload: '{ "fields": "' + fields + '"}' };
var options = {
'method': 'post',
'payload': payload
};
UrlFetchApp.fetch(POST_URL, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment