Dustin Wyatt
Dustin Wyatt

Reputation: 4244

How to join a Slack channel as a Real Time Messaging bot user?

channels.join is not allowed for bot users. I would like my RTM-using bot to listen to channels other than the one listed in the bot integration page.

I don't see a way to change the channels in the bot integration page:

bot integration page

Is this just a limitation of bots or am I missing something fundamental here?

Upvotes: 31

Views: 12769

Answers (3)

Dragoe
Dragoe

Reputation: 171

This is still a limitation of bots as of May 2017 because of a bug that it introduces-- see paulhammod's answer at https://github.com/slackapi/node-slack-sdk/issues/26. The correct way to add a bot is the the slash command /invite @<bot.user> <channel_name> as @MattGifford pointed out.

However, @nafg introduced an interesting workaround. If you generate a personal API_TOKEN for your account, then you can use it to invite a bot. For instance, in python one could run:

import slackclient sc = slackclient.SlackClient(<PERSONAL_API_TOKEN>) sc.api_call('channels.invite', channel=<channel_id>, user=<user_id>)

This will invite the bot to the channel. If you wanted to automate inviting your bot to new channels, you can look at event listeners in the API found at https://api.slack.com/rtm

As long as you allow your API_TOKEN to be used for that purpose, it seems that it would work as needed, albeit less convenient.

Upvotes: 4

nafg
nafg

Reputation: 2534

I haven't actually tried this but I would expect that you can first call channels.join on behalf of an actual user (e.g., yourself), then call channels.invite as that user to add the bot to that channel. I expect that is allowed, and it would then allow the bot to interact with that channel. This way you can automate everything.

Upvotes: 0

Matt Gifford
Matt Gifford

Reputation: 581

I had the same issue and wasnt sure why my bot was only listening to certain channels.

Your bot will need to be invited to each channel by a user. Run this command within the required channel in the Slack app to do so

/invite @<your_bot_name>

Once in the channel they should then be able to listen to events.

Upvotes: 53

Related Questions