Skip to content

Instantly share code, notes, and snippets.

@mstraughan86
Last active October 8, 2017 00:12
Show Gist options
  • Save mstraughan86/055588503a335ec23262493262b8615f to your computer and use it in GitHub Desktop.
Save mstraughan86/055588503a335ec23262493262b8615f to your computer and use it in GitHub Desktop.
Slack Playground

@see: slackapi/hubot-slack#105 (comment)

I needed this functionality too, so I ended up working around this by writing a standalone PHP script 
to automatically invite the bot into every channel. If I get time I'll convert it into node.js.

It essentially just uses the Web API to pull down a list of all channels:

https://slack.com/api/channels.list?token=MY_TOKEN
This gives me the Slack ID for every channel (ie "A12B45C789"), as well as which Users are members of that Channel.

I can then send a second API request to invite my bot into every channel which it isn't already a member of.

https://slack.com/api/channels.invite?token=MY_TOKEN&channel=A12B45C789&user=U123456789
(the user parameter is the Slack ID of my bot).

It's clunky but it works. Currently running it as a scheduled cron job but would eventually prefer to use 
a webhook (listening for a channel created event).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment