Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Easily send Slack invites, right from Google Forms.
Google Apps Script for sending Slack invites
Or, "I love saving people precious seconds and clicks because I'm just altruistic like that"
This is really simple but takes a bit of explaining.
You will need to paste this into the Google spreadsheet where Forms is dumping responses, and
then update the values below as described.
Charlton Trezevant 2017 - MIT License
function onFormSubmit(e) {
/* Note: You can either use a numeric index from e.values
(which sorts response values by question order), or you
have the option of using named values a la e.namedValues['Email'][0]
The below will most likely have to be updated depending on your form's layout
var email = e.values[3];
function sendSlackInvite(email){
/* So, the way this works is by hitting an API endpoint that's technically not public,
but Slack is nice and doesn't care.
This does require a legacy API token from a user account with permissions to invite new users.
I'd recommend making a new one so real admins aren't pasting their API tokens into random scripts.
var TOKEN = "xoxp-blahblahblah";
// Slack will automatically add users to the default channels specified in your instance's settings,
// however you can also specify additional channels to auto-add them to here, per-invite.
var CHANNELS = "C1Y33TF4KE";
try {
} catch(e) {
// Do nothing.
Logger.log("Slack API call caused an error:" + JSON.stringify(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment