Skip to content

Instantly share code, notes, and snippets.

@imdanielch
Forked from furf/how-to.md
Created March 30, 2018 19:40
Show Gist options
  • Save imdanielch/6491fa4b06d930f7291924cdee3cc216 to your computer and use it in GitHub Desktop.
Save imdanielch/6491fa4b06d930f7291924cdee3cc216 to your computer and use it in GitHub Desktop.
Slack invite integration for Google Forms
  1. Create a Google Form with a field to collect email addresses. Pro-tip: use Data Validation to validate string is valid email.
  2. Click View Responses to view form responses in Google Spreadsheets.
  3. Open menu Tools > Script editor...
  4. Paste in Google App Script below and make the following changes:
    • Create a Slack API token and replace the value of SLACK_API_TOKEN.
    • Replace "YOUR_TEAM_NAME" with your team's name in the value for SLACK_API_INVITE_URL.
    • Make sure EMAIL_FIELD_NAME corresponds to the header text of your Google Spreadsheet's email column.
  5. Open menu Resources > Current project's triggers and add a new trigger: onFormSubmit, From spreadsheet, On form submit. Click Save and accept the authorization request to use the script.
  6. You can optionally configure notifications to receive error messages by email.
var SLACK_API_TOKEN = 'xxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxx-xxxxxxxxxx';
var SLACK_API_INVITE_URL = 'https://YOUR_TEAM_NAME.slack.com/api/users.admin.invite';
var EMAIL_FIELD_NAME = 'E-mail Address';
function inviteUser(email) {
var data = {
email: email,
token: SLACK_API_TOKEN,
set_active: 'true'
};
var options = {
method: 'POST',
payload: data
};
UrlFetchApp.fetch(SLACK_API_INVITE_URL, options);
}
function onFormSubmit(e) {
var email = e.namedValues[EMAIL_FIELD_NAME][0];
inviteUser(email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment