aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-08-26 22:50:30 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit6722517e91c19cc7c1d39335a1b64020ac7c0b9b (patch)
treeacf1b38f7b31692dc2d8d76dada08e14af53dd0e /slack
parentfe5bc258fdef24fb063305080a309336244dbfb2 (diff)
downloadwee-slack-6722517e91c19cc7c1d39335a1b64020ac7c0b9b.tar.gz
Fetch usergroups at startup if edgeapi isn't available
Diffstat (limited to 'slack')
-rw-r--r--slack/slack_api.py4
-rw-r--r--slack/slack_workspace.py7
2 files changed, 11 insertions, 0 deletions
diff --git a/slack/slack_api.py b/slack/slack_api.py
index 890d4d9..9638e58 100644
--- a/slack/slack_api.py
+++ b/slack/slack_api.py
@@ -42,6 +42,10 @@ class SlackApiCommon:
class SlackEdgeApi(SlackApiCommon):
+ @property
+ def is_available(self) -> bool:
+ return self.workspace.config.api_token.value.startswith("xoxc-")
+
async def _fetch_edgeapi(self, method: str, params: EdgeParams = {}):
enterprise_id_part = (
f"{self.workspace.enterprise_id}/" if self.workspace.enterprise_id else ""
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index d659317..a570658 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -216,6 +216,13 @@ class SlackWorkspace:
await self._connect_ws(rtm_connect["url"])
+ if not self.api.edgeapi.is_available:
+ usergroups = await self.api.fetch_usergroups_list()
+ for usergroup in usergroups["usergroups"]:
+ future = Future[SlackUsergroup]()
+ future.set_result(SlackUsergroup(self, usergroup))
+ self.usergroups[usergroup["id"]] = future
+
users_conversations_response = await self.api.fetch_users_conversations(
"public_channel,private_channel,mpim,im"
)