Last active
October 8, 2020 18:53
-
-
Save TkTech/3edcb2f46a93843686a062dbaf5367a6 to your computer and use it in GitHub Desktop.
Post the results of a Google Form to a Slack channel webhook
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
var webhook = 'https://hooks.slack.com/services/***'; | |
var header = 'A user requested an integration be reviewed.'; | |
var whoLeader = 'Review requested by:'; | |
function OnSubmit(e) { | |
var responses = e.response.getItemResponses(); | |
UrlFetchApp.fetch(webhook, { | |
method: 'post', | |
payload: JSON.stringify({ | |
'blocks': [{ | |
'type': 'header', | |
'text': { | |
'type': 'plain_text', | |
'text': header | |
} | |
}, { | |
'type': 'section', | |
'fields': [{ | |
'type': 'plain_text', | |
'text': whoLeader | |
}, { | |
'type': 'plain_text', | |
'text': e.response.getRespondentEmail() | |
}] | |
}].concat(makeBlocks(responses)) | |
}) | |
}); | |
} | |
var makeBlocks = function(responses) { | |
var fields = []; | |
for (var i = 0; i < responses.length; i++) { | |
var response = responses[i]; | |
var question = response.getItem().getTitle(); | |
// For most response types, this gives you a nice simple string. | |
// 3 types give more complicated objects, which we do not yet handle: | |
// - CheckboxItem | |
// - GridItem | |
// - CheckboxGridItem | |
var answer = response.getResponse(); | |
fields.push({ | |
'type': 'section', | |
'fields': [{ | |
'type': 'plain_text', | |
'text': question | |
}, { | |
'type': 'plain_text', | |
'text': answer | |
}] | |
}); | |
} | |
return fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment