diff options
-rw-r--r-- | slack/slack_api.py | 3 | ||||
-rw-r--r-- | slack/slack_workspace.py | 4 | ||||
-rw-r--r-- | typings/slack_api/slack_users_conversations.pyi | 114 |
3 files changed, 120 insertions, 1 deletions
diff --git a/slack/slack_api.py b/slack/slack_api.py index 4d8df43..aeaf6be 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -9,6 +9,7 @@ from slack.shared import shared if TYPE_CHECKING: from slack_api.slack_conversations_info import SlackConversationsInfoResponse + from slack_api.slack_users_conversations import SlackUsersConversationsResponse from slack.slack_conversation import SlackConversation from slack.slack_user import SlackUser @@ -65,7 +66,7 @@ class SlackApi: exclude_archived: bool = True, limit: int = 1000, pages: int = -1, - ) -> Any: + ) -> SlackUsersConversationsResponse: return await self._fetch_list( "users.conversations", "channels", diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 72ffc7d..e659eba 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -42,6 +42,10 @@ class SlackWorkspace: user_channels_response = await self.api.fetch_users_conversations( "public_channel" ) + if user_channels_response["ok"] is False: + # TODO: Handle error + return + user_channels = user_channels_response["channels"] for channel in user_channels: diff --git a/typings/slack_api/slack_users_conversations.pyi b/typings/slack_api/slack_users_conversations.pyi new file mode 100644 index 0000000..ec394a0 --- /dev/null +++ b/typings/slack_api/slack_users_conversations.pyi @@ -0,0 +1,114 @@ +from __future__ import annotations + +from typing import Generic, List, Literal, TypedDict, TypeVar, final + +T = TypeVar("T") + +@final +class SlackTopic(TypedDict): + value: str + creator: str + last_set: int + +@final +class SlackPurpose(TypedDict): + value: str + creator: str + last_set: int + +class SlackUsersConversationsCommon(TypedDict): + id: str + created: int + is_archived: bool + is_org_shared: bool + context_team_id: str + updated: int + +class SlackUsersConversationsCommonNotIm(SlackUsersConversationsCommon): + name: str + is_channel: bool + is_group: bool + is_im: Literal[False] + is_general: bool + unlinked: int + name_normalized: str + is_shared: bool + is_pending_ext_shared: bool + pending_shared: List # pyright: ignore [reportMissingTypeArgument] + parent_conversation: None + creator: str + is_ext_shared: bool + shared_team_ids: List[str] + pending_connected_team_ids: List # pyright: ignore [reportMissingTypeArgument] + topic: SlackTopic + purpose: SlackPurpose + +@final +class SlackUsersConversationsPublic(SlackUsersConversationsCommonNotIm): + is_mpim: Literal[False] + is_private: Literal[False] + previous_names: List[str] # TODO: Check if private and mpim has this + +@final +class SlackUsersConversationsPrivate(SlackUsersConversationsCommonNotIm): + is_mpim: Literal[False] + is_private: Literal[True] + +@final +class SlackUsersConversationsMpim(SlackUsersConversationsCommonNotIm): + is_mpim: Literal[True] + is_private: Literal[True] + +@final +class SlackUsersConversationsIm(SlackUsersConversationsCommon): + is_im: Literal[True] + user: str + is_user_deleted: bool + priority: int + +SlackUsersConversationsNotIm = ( + SlackUsersConversationsPublic + | SlackUsersConversationsPrivate + | SlackUsersConversationsMpim +) +SlackUsersConversations = SlackUsersConversationsNotIm | SlackUsersConversationsIm + +@final +class SlackUsersConversationsErrorResponse(TypedDict): + ok: Literal[False] + error: str + +@final +class SlackResponseMetadata(TypedDict): + next_cursor: str + +@final +class SlackUsersConversationsSuccessResponse(TypedDict, Generic[T]): + ok: Literal[True] + channels: List[T] + response_metadata: SlackResponseMetadata + +SlackUsersConversationsPublicResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversationsPublic] + | SlackUsersConversationsErrorResponse +) +SlackUsersConversationsPrivateResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversationsPrivate] + | SlackUsersConversationsErrorResponse +) +SlackUsersConversationsMpimResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversationsMpim] + | SlackUsersConversationsErrorResponse +) +SlackUsersConversationsImResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversationsIm] + | SlackUsersConversationsErrorResponse +) +SlackUsersConversationsNotImResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversationsNotIm] + | SlackUsersConversationsErrorResponse +) +SlackUsersConversationsResponse = ( + SlackUsersConversationsSuccessResponse[SlackUsersConversations] + | SlackUsersConversationsErrorResponse +) |