Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ZackStone/1c7c2f7ac98520c9c84d536880f96770 to your computer and use it in GitHub Desktop.
Save ZackStone/1c7c2f7ac98520c9c84d536880f96770 to your computer and use it in GitHub Desktop.
Invite all team members to a Slack channel
/*
https://webapps.stackexchange.com/questions/100820/how-do-i-invite-all-team-members-to-a-new-slack-channel#answer-104062
Instructions: Just browse to the appropriate channel and paste
this script (below) into your Chrome/Firefox dev console and hit enter.
Then wait for the script to run until it completes.
It might take time as there is a limit to how many users may be invited at once.
The script will loop until all team members are invited.
*/
var foundAny=false;
function selectAllByLetter(remainingLetters) {
console.log(remainingLetters)
var letter = remainingLetters.pop();
$("#channel_invite_filter").val(letter).trigger("input");
setTimeout(function() {
$(".channel_invite_member:not(hidden)").each(function(i, obj) {
foundAny=true;
this.click();
});
if (remainingLetters.length) {
selectAllByLetter(remainingLetters);
} else {
setTimeout(function() {
console.log("Inviting them all!")
$('.invite_go').click()
},400)
}
},300);
}
function inviteAllUsers() {
foundAny=false;
setTimeout(function () {
setTimeout(function() {
$('#channel_actions_toggle').click();
},100)
setTimeout(function() {
$('#channel_invite_item').click();
},200)
//Enter each letter to trigger searches
var remainingLetters = ["a","b","c","d","e","f","g","h","i","j","v","k","l","m","n","o","p","q","r","s","t","u","v","z"];
selectAllByLetter(remainingLetters);
if (foundAny) {
inviteAllUsers();
}
}, 4000);
}
inviteAllUsers();
@owocki
Copy link

owocki commented Mar 13, 2018

also it seems that slack has updated this form so that 1 char input (a,b,c) won't be accpeted anymore.. my above script enumerates all the possible 2-char strings

@stevenmirabito
Copy link

@owocki Thanks, saved me from writing that up myself - worked like a charm! Do note that the above will invite all of your multi-channel guests as well, which may or may not be desired behavior.

@grantbrokergenius
Copy link

grantbrokergenius commented Aug 23, 2018

Last one was still missing a few characters in the search..

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
var letters = 'abcdefghijklmnopqrstuvwxyz';
async function inviteAllUsers() {      
   for(var i = 0; i < letters.length; i++){
      await sleep(300);
    $('#channel_actions_toggle').click();
      await sleep(300);
    $('#channel_invite_item').click();
      await sleep(300);
     for(var k = 0; k < letters.length; k++){
        var word = letters[i] + letters[k];
        await sleep(300);
        $("#channel_invite_filter").val(word).trigger("input");
        $(".channel_invite_member:not(hidden)").each(function(i, obj) {
            foundAny=true;
            this.click();
        });
      }
      await sleep(300);
      $('.invite_go').click()
    }
}

inviteAllUsers(); 
setInterval(inviteAllUsers,600*1000);

@EliasJorgensen
Copy link

Slack must have updated their frontend, as now jQuery is no longer included in the codebase.
Therefore, this no longer works. 😞

@leefuhr
Copy link

leefuhr commented Sep 23, 2019

Slack must have updated their frontend, as now jQuery is no longer included in the codebase.
Therefore, this no longer works. 😞

And that Chrome extension 404s now. We are without hope!

@jaipandya
Copy link

You can use Channel Tools, which is a Slack app, to invite all users to a Slack channel. Because the app relies on Slack API as opposed to its UI, you can trust that it won't break like all other solutions until now.

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