From a46a81e29e2eb6df2e77f3fae13ffad690688e88 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 7 Jan 2024 15:51:33 +0100 Subject: Only open channels for the current sub workspace It's possible to have a token that's only for one workspace in an enterprise grid. For me with such a token, it returns channels in all workspaces in client.userBoot, but only channels in the tokens workspace in client.counts. This meant that we didn't get last_read for all channels we opened, and additionally some methods like conversations.members would fail with "channel_not_found" for those channels. This filters the channels from client.userBoot by checking that the channel is in the current sub workspace, if the token we're using is not an org level (for all workspaces the user is in) token. Additionally it raises an error if any of the channels to open isn't included in the response from client.counts to prevent missing last_read for any channels if there are other channels that isn't included. I could have filtered the list of channels to open by the channels included from client.counts, but I don't want any channels to just silently be ignored. --- slack/slack_api.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'slack/slack_api.py') diff --git a/slack/slack_api.py b/slack/slack_api.py index 76d97cb..2f57e61 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -23,6 +23,7 @@ if TYPE_CHECKING: from slack_api.slack_conversations_replies import SlackConversationsRepliesResponse from slack_api.slack_emoji import SlackEmojiListResponse from slack_api.slack_rtm_connect import SlackRtmConnectResponse + from slack_api.slack_team_info import SlackTeamInfoResponse from slack_api.slack_usergroups_info import SlackUsergroupsInfoResponse from slack_api.slack_users_conversations import SlackUsersConversationsResponse from slack_api.slack_users_info import SlackUserInfoResponse, SlackUsersInfoResponse @@ -129,6 +130,13 @@ class SlackApi(SlackApiCommon): return response return response + async def fetch_team_info(self): + method = "team.info" + response: SlackTeamInfoResponse = await self._fetch(method) + if response["ok"] is False: + raise SlackApiError(self.workspace, method, response) + return response + async def fetch_rtm_connect(self): method = "rtm.connect" response: SlackRtmConnectResponse = await self._fetch(method) -- cgit