HomeDesignCodeWriting
Daniel Schwarz

How to Enable Slack Auto-Signup with Google Forms/Sheets

As a digital nomad, I enjoy spending time on #hashtagnomad, a digital nomad community that leverages the features of a Slack team. Slack doesn't typically allow auto-signups, but with a bit of hacking and a TypeForm integration, it can be done.

Essentially, it allows anybody to build their own little community on Slack.

So, I built a Slack community for writers, although I used Google Forms and Google Sheets for the invite functionality as it's free, and I also used Zapier and MailerLite to collect the email addresses, which are used to send out the monthly newsletter.

Here's how I did it.

Google Form > Google Sheet

It starts with a no-fuss Google Form, where the user submits only their email address. Given any more more roadblocks than that, users are likely to turn away, so I wanted to keep it relatively simple. Next, the email address needs to be copied into a Google Sheet, which of course is automated as well. Here's how:

  • Click the menu icon and choose "Select response destination"

Select response destination

  • Choose either "Create a new spreadsheet" or "Select existing spreadsheet"

Create new Google spreadsheet

  • Click the Google Sheets icon to open your spreadsheet

Click the sheet icon

Google Sheet > Slack Invite

Now we need to run some JavaScript code that accesses the hidden Slack API (don't worry—if you don't code, you'll only have to tweak a couple of things). From the Google Sheets menu, navigate to Tools → Script editor… and copy in the following:

// secrets

var SlackName = ""; // name of your slack
var SlackToken = ""; // Slack auth token

// end secrets

function Initialize() {

  var triggers = ScriptApp.getProjectTriggers();

  for (var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
  }

  ScriptApp.newTrigger("onFormSubmitEx")
    .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
    .onFormSubmit().create();

}

function post(url, payload) {

  var options =
      {
        "method"  : "POST",
        "payload" : payload,   
        "followRedirects" : true,
        "muteHttpExceptions": true
      };

  var result = UrlFetchApp.fetch(url, options);
  return result.getContentText();
}

function onFormSubmitEx(e) {

  var timestamp = e.values[0];
  var toAddress = e.values[1];
  var slackInviteUrl = "https://" + SlackName + ".slack.com/api/users.admin.invite";

  var curlStatus = post(slackInviteUrl, {
    token: SlackToken,
    email: toAddress
  });
}

What this does, is listens for new rows added to the spreadsheet (new signups) and sends a Slack invite to that email address. Make sure to insert your Slack name and Slack token into the code at the top. You can obtain your Slack token here.

And we're done 👏👏👏

P.S. you can use Zapier to add additional functionality to your sheets. For example, I use Zapier to sync email addresses from Google Sheets into Mailerlite (for our community newsletter). Here's a zap that syncs your Sheets with MailChimp!

Subscribe to my newsletter

Get writing or design tips in your inbox, or follow my nomad adventures

Subscribe
Next up: Upwork Sucks—Here's How to Really Find Paid Writing Jobs