Auto-invite members to Slack on Laddr registration

laddr-plugins

#1

Here’s a quick plugin that will make Laddr automatically invite users to your Slack workspace when they register.

Note: If you have a Premium Slack workspace that supports SSO you can use Laddr as an SSO provider instead with no need for invites. Check out this guide for using Laddr with Slack SSO.


Getting started — Get a Slack API Token!

You will need a legacy API token (which you will enter for the $token var) which you can acquire here.

Crate a new file

/event-handlers/Emergence/People/RegistrationRequestHandler/registerComplete/slackinvite.php

<?php

$token = "YOUR_SLACK_TOKEN_HERE";
$url = 'https://slack.com/api/users.admin.invite?' . http_build_query([
    'token' => $token,
    'email' => $_EVENT['User']->Email
]);

$result = file_get_contents($url, null, stream_context_create(array(
    'http' => array(
        'protocol_version' => 1.1,
        'user_agent'       => 'PHP-LADDR/2.0',
        'method'           => 'POST',
        'header'           => "Content-type: application/json\r\n".
                              "Connection: close"
    ),
)));

Enjoy :smiley:


#2

I’d recommend doing this instead for that line to ensure any characters in the email address get encoded as needed:

<?php
$url = 'https://slack.com/api/users.admin.invite?' . http_build_query([
    'token' => $token,
    'email' => $_EVENT['User']->Email
]);