Does Slack provide a method that allows me to retrieve a list of all joined channels of a user or bot?
I am unable to find a proper API method and want to avoid using either the default channel.list or group.list since it would be expensive to execute 2 api calls and crawl through all channels and match the members ids, possibly even use pagination because of the member array limits of each channel.
There is no single API method that gives you all joined channels of a user / bot with a single API call.
The quickest methods (with two API calls) is indeed calling channels.list and groups.list and matching the result against your user ID, however this is not the recommend approach due to the recently introduced member cap to max. 500 members per channel. Note that this is a hard cap (!!), so you can't get additional members by pagination.
The recommended approach is to use the newer conversations methods, which have the benefit to work for both public and private channels and will return the complete list of members (with pagination).
However, this approach will require even more API calls:
Get list of all public and private channels with conversations.list
Get members per channel with conversations.members per channel
Compile list of channels per user by comparing user ID with all
members of all channels.
If you feel that this function is missing in the API I would recommend sending a feature request to the Slack team.
Related
Is there a way to get historical call ID's from the Slack API?
I would like to use the slack calls.info API (https://api.slack.com/methods/calls.info) to get information on past Slack calls. But I cannot find a way to get the ID's of the calls. (The only way per the documentation is the data returned by the calls.add API
I can see evidence in Slack of my past calls with other users, but when I call conversations.history, I do not see any data for calls...just messages.
Unfortunately, there is no method that will return call ids retroactively.Something like calls.list would be helpful. Right now, I think your only option would be to store the ids when you call calls.addmoving forward so that you can then use them in future calls.info calls.
Whenever there is a channel with the name that matches a certain regex, we want to add a certain group of members to these channel automatically. For example, if a new slack channel with the name that matches the regex INC-.* is created, slack group #incidentmembers will be added to that new slack channel automatically
Is there a way to configure this in Slack?
There's no native way to do this in Slack, but you could build something using the public APIs. Specifically you would
Listen to the channel_created event which fires when a public channel is created, which you can then regex as you see fit.
Grab the membership of the relevant User Group using usergroups.users.list (if the membership is static you could probably skip this)
Use conversations.invite to add the users to the channel
One limitation of this approach is that you won't get channel_created events for private channels. There's no way around this I'm afraid.
I am trying to get a list of members in Microsoft teams graph API. I did not find anything in the official documents. I am able to get list of teams and channel but I need to get the list of members to belong to the specific channel. Can anyone have an idea how can I get that?
Public channels don't have "members". The Team (basically group) has members. So you can find the list of members of a channel by listing the group members.
To support Private channels you need to use the beta API.
There is no documented API to list the private channel members, but reading between the lines of the Private Channel Add Member API, my guess that if you do a:
GET https://graph.microsoft.com/beta/teams/<group_id>/channels/<channel_id>/members
you will get a list of private members. In fact it's documented here at the bottom of the page.
i am trying to use the API to get the total number of messages posted by each user during a certain period. Ideally, I would be able to break the number of messages by the type of channel (public, private, direct messages.) Is this possible? I am looking through the API documentation but haven't found anything. I would be using it to create a script that would automatically generate weekly activity reports.
Thank you for any advice you can provide!
There is no special endpoint for this information as far as I know, but you can generate something similar yourself by looping though all channels and counting the message per user, e.g.
Get list of all channels with conversations.list
Get history of each channel with conversations.history
Count messages per user
Of course your results would not include message from channels, that your bot has no access too (e.g. some private channels, direct message channels).
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?
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.
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:
Get the list of all conversations from conversations.list
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.
FYI you can now list user channels/conversations using:
https://api.slack.com/methods/users.conversations