Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of channels a user is a member of

Writing a slack bot and I would like to be able to get a list of all the channels my bot is a member of. One way to do this is to call https://slack.com/api/channels.list, get a (potentially large) list of all channels and then search for the channels that the current (bot) user is a member of. This works fine, but seems very heavy handed.

Is there a better way? To get just the channels that a given user is a member of?

like image 355
Matt Burland Avatar asked Dec 11 '17 21:12

Matt Burland


People also ask

Can you see what Slack channels someone is in?

One way to do this is to call https://slack.com/api/channels.list , get a (potentially large) list of all channels and then search for the channels that the current (bot) user is a member of.


2 Answers

I think users.conversations is what you're looking for. Without additional params it will return all public channels the calling user is a member of.

like image 113
Nico Durstewitz Avatar answered Oct 20 '22 03:10

Nico Durstewitz


No, there is no shorter way to get this information.

Actually, Slack recommends to use the new conversations methods for this task, since the members property in all other methods, e.g. channels.list has recently been changed to only return a truncated user list. See here for details.

With conversations you have to make an additional call per channel to get all channels a user is a member of. However it will work with all types of channels (e.g. public channels, private channels) at the same time.

The basic approach is:

  1. Get the list of all conversations from conversations.list

  2. Get the list of members per conversation form conversations.members.

So if you want your Slack app to be future proof and also work with large number of users better use the conversations methods for your task.

like image 20
Erik Kalkoken Avatar answered Oct 20 '22 02:10

Erik Kalkoken