Skip to content

Instantly share code, notes, and snippets.

@furf
Last active June 27, 2022 01:57
Show Gist options
  • Save furf/174ae7db1fef79468c8f to your computer and use it in GitHub Desktop.
Save furf/174ae7db1fef79468c8f 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);
}
@alexlyzhov
Copy link

alexlyzhov commented Jun 27, 2022

Relevant links:
https://api.slack.com/authentication/token-types
https://api.slack.com/docs/rate-limits
https://api.slack.com/methods/admin.users.invite
The last one says it's only available for "Enterprise Grid".

The schema has changed a bit so it's definitely not plug-and-play anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment