Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically request to join channels #14

Open
lucymhdavies opened this issue Jun 7, 2018 · 4 comments
Open

Automatically request to join channels #14

lucymhdavies opened this issue Jun 7, 2018 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@lucymhdavies
Copy link
Contributor

lucymhdavies commented Jun 7, 2018

The welcomebot bot user should be able to automatically join (public) channels when it starts up.

Unfortunately, if Welcomebot is run with a Bot user token, it will not have permission to invite itself to a channel.

You can post to any public channel through the REST API, so instead we could do something like...

  • Iterate through all channels.
  • For all channels the bot is not a member of, post a message like:
  • "Hi! I need an invite to this channel!" (which should be overrideable in config.json)

Original description:

The welcomebot bot user should be able to automatically join (public) channels when it starts up.

This way, you only need to edit the config, and if you forget to invite the bot to the channel it won't matter.

The simplest method of doing this could be, when starting up, iterate through all channels in the config and attempt to join them, handling errors without killing the entire app.
https://api.slack.com/methods/channels.join implies that no error will be thrown if the user is already in the channel.

The slack library we're using has the following we can use:

// JoinChannel joins the currently authenticated user to a channel
// see https://api.slack.com/methods/channels.join
func (api *Client) JoinChannel(channelName string) (*Channel, error) {
	return api.JoinChannelContext(context.Background(), channelName)
}

This probably won't work for private channels, so handle those errors gracefully.

@lucymhdavies
Copy link
Contributor Author

lucymhdavies commented Aug 6, 2018

#17 looks like it should work, and indeed I can see from our logs that the bot is attempting to join specific channels:

8/6/2018 5:17:59 PMERRO[0000] Error joining public channel welcomebot-test: not_allowed_token_type
8/6/2018 5:17:59 PMERRO[0000] Error joining public channel announcements: not_allowed_token_type

As it happens, we're running our version of this with a bot token, which doesn't actually have permissions to join channels.

https://api.slack.com/methods/channels.join is the API method needed, listed as restricted to user tokens :(

And bot users do not have this permission:
https://api.slack.com/bot-users#methods

So we may need to look into how we have this deployed in our Slack workspace (and add something to README.md)

@liamphmurphy
Copy link
Contributor

liamphmurphy commented Aug 6, 2018

Interesting issue. In my testing, I was indeed using a 'normal' account, which explains why it worked on my end. So, hypothetically, only the JoinChannel method needs to be replaced?

Out of curiosity: could someone manually invite the bots once, and the bots can rejoin in the future, or does that not work?

@heyitsols
Copy link
Contributor

Given that the join channel method isn't available to bots – makes sense for security I guess, seeing as it could join public channels without an invitation and read messages – I'm not sure if there is another way to fudge it to work :(

@lucymhdavies
Copy link
Contributor Author

You can post to any public channel through the REST API, so I'm wondering if we could change it to something like...

Iterate through all channels.
For all channels the bot is not a member of, post a message like:
"Hi! I need an invite to this channel!" (which should be overrideable in config.json)

@lucymhdavies lucymhdavies added good first issue Good for newcomers and removed good first issue Good for newcomers labels Nov 27, 2018
@lucymhdavies lucymhdavies changed the title Automatically join channels Automatically request to join channels Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants