Last active
February 15, 2024 07:53
-
-
Save andychase/e0b1eaa1b9ecc00ef2d2 to your computer and use it in GitHub Desktop.
Google Forms Slack Notification
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
// 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 response = e.response.getItemResponses(); | |
// Setup 2: | |
// Modify the below to make the message you want. | |
// See: https://developers.google.com/apps-script/reference/forms/form-response | |
var d = e.response.getRespondentEmail() + " | " + response[0].getResponse(); | |
var payload = | |
{ "payload": '{"text": "' + d + '"}' } | |
var options = | |
{ | |
"method" : "post", | |
"payload" : payload | |
}; | |
UrlFetchApp.fetch(POST_URL, options); | |
}; |
I try the above script but give 400 response the Post call, and then I update this:
var payload =
{
"text": d
}
var options =
{
'method' : "POST",
'contentType': 'application/json',
'payload' : JSON.stringify(payload)
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like Google changed their menu organization, so line 5 should be:
("Current project triggers" is under "Edit", not "Resources".) After that it worked like a charm. Thanks for sharing!