diff options
-rw-r--r-- | slack/slack_conversation.py | 18 | ||||
-rw-r--r-- | slack/slack_message.py | 23 | ||||
-rw-r--r-- | slack/slack_workspace.py | 4 | ||||
-rw-r--r-- | typings/slack_api/slack_conversations_history.pyi | 45 | ||||
-rw-r--r-- | typings/slack_rtm/slack_rtm_message.pyi | 31 |
5 files changed, 119 insertions, 2 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 211d156..01a1fc8 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -3,7 +3,7 @@ from __future__ import annotations import time from collections import OrderedDict from contextlib import contextmanager -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List, Optional, Union import weechat @@ -14,7 +14,12 @@ from slack.util import get_callback_name if TYPE_CHECKING: from slack_api.slack_conversations_info import SlackConversationsInfo - from slack_rtm.slack_rtm_message import SlackMessageChanged, SlackMessageDeleted + from slack_rtm.slack_rtm_message import ( + SlackMessageChanged, + SlackMessageDeleted, + SlackShRoomJoin, + SlackShRoomUpdate, + ) from typing_extensions import Literal from slack.slack_api import SlackApi @@ -399,6 +404,15 @@ class SlackConversation: message.deleted = True await self.rerender_message(message) + async def update_message_room( + self, data: Union[SlackShRoomJoin, SlackShRoomUpdate] + ): + ts = SlackTs(data["room"]["thread_root_ts"]) + message = self._messages.get(ts) + if message: + message.update_message_json_room(data["room"]) + await self.rerender_message(message) + async def reaction_add(self, message_ts: SlackTs, reaction: str, user_id: str): message = self._messages.get(message_ts) if message: diff --git a/slack/slack_message.py b/slack/slack_message.py index 94f0501..d9c1715 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -29,6 +29,7 @@ if TYPE_CHECKING: SlackMessageBlockRichTextList, SlackMessageBlockRichTextSection, SlackMessageReaction, + SlackMessageSubtypeHuddleThreadRoom, ) from typing_extensions import assert_never @@ -140,6 +141,11 @@ class SlackMessage: self._rendered_prefix = None self._rendered_message = None + def update_message_json_room(self, room: SlackMessageSubtypeHuddleThreadRoom): + if "room" in self._message_json: + self._message_json["room"] = room + self._rendered_message = None + def _get_reaction(self, reaction_name: str): for reaction in self._message_json.get("reactions", []): if reaction["name"] == reaction_name: @@ -285,6 +291,23 @@ class SlackMessage: return f"{await self._nick()} {text_action} {text_conversation_name}{inviter_text}" + elif ( + "subtype" in self._message_json + and self._message_json["subtype"] == "huddle_thread" + ): + room = self._message_json["room"] + team = self._message_json["team"] + + huddle_text = "Huddle started" if not room["has_ended"] else "Huddle ended" + name_text = f", name: {room['name']}" if room["name"] else "" + texts: List[str] = [huddle_text + name_text] + + for channel_id in room["channels"]: + texts.append( + f"https://app.slack.com/client/{team}/{channel_id}?open=start_huddle" + ) + return "\n".join(texts) + else: if "blocks" in self._message_json: texts = await self._render_blocks(self._message_json["blocks"]) diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index b730987..ad36c3d 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -277,6 +277,8 @@ class SlackWorkspace: return elif data["type"] == "reaction_added" or data["type"] == "reaction_removed": channel_id = data["item"]["channel"] + elif data["type"] == "sh_room_join" or data["type"] == "sh_room_update": + channel_id = data["huddle"]["channel_id"] elif "channel" in data and type(data["channel"]) == str: channel_id = data["channel"] else: @@ -311,6 +313,8 @@ class SlackWorkspace: await channel.reaction_remove( SlackTs(data["item"]["ts"]), data["reaction"], data["user"] ) + elif data["type"] == "sh_room_join" or data["type"] == "sh_room_update": + await channel.update_message_room(data) elif data["type"] == "user_typing": await channel.typing_add_user(data["user"], data.get("thread_ts")) else: diff --git a/typings/slack_api/slack_conversations_history.pyi b/typings/slack_api/slack_conversations_history.pyi index cfb4a8a..f484ade 100644 --- a/typings/slack_api/slack_conversations_history.pyi +++ b/typings/slack_api/slack_conversations_history.pyi @@ -341,6 +341,50 @@ class SlackMessageWithFiles(SlackMessageCommon): class SlackMessageWithFilesFinal(SlackMessageWithFiles): pass +class SlackMessageSubtypeHuddleThreadRoom(TypedDict): + id: str + name: str + media_server: str + created_by: str + date_start: int + date_end: int + participants: List[str] + participant_history: List[str] + participants_camera_on: List[str] + participants_camera_off: List[str] + participants_screenshare_on: List[str] + participants_screenshare_off: List[str] + canvas_thread_ts: str + thread_root_ts: str + channels: List[str] + is_dm_call: bool + was_rejected: bool + was_missed: bool + was_accepted: bool + has_ended: bool + background_id: str + canvas_background: str + is_prewarmed: bool + is_scheduled: bool + attached_file_ids: List[str] + media_backend_type: str + display_id: str + external_unique_id: str + app_id: str + call_family: str + pending_invitees: Dict[str, str] + +class SlackMessageSubtypeHuddleThread(SlackMessageStandardCommon): + subtype: Literal["huddle_thread"] + channel: str + permalink: str + no_notifications: bool + room: SlackMessageSubtypeHuddleThreadRoom + +@final +class SlackMessageSubtypeHuddleThreadFinal(SlackMessageSubtypeHuddleThread): + pass + # TODO: Add other subtypes class SlackMessageSubtypeBotMessage(SlackMessageCommon): subtype: Literal["bot_message"] @@ -395,6 +439,7 @@ SlackMessage = ( | SlackMessageThreadParentNotSubscribedFinal | SlackMessageThreadParentSubscribedFinal | SlackMessageWithFilesFinal + | SlackMessageSubtypeHuddleThreadFinal | SlackMessageSubtypeBotMessageFinal | SlackMessageSubtypeBotRemoveFinal | SlackMessageSubtypeBotAddFinal diff --git a/typings/slack_rtm/slack_rtm_message.pyi b/typings/slack_rtm/slack_rtm_message.pyi index 1fae2d6..9ad3ce1 100644 --- a/typings/slack_rtm/slack_rtm_message.pyi +++ b/typings/slack_rtm/slack_rtm_message.pyi @@ -7,6 +7,8 @@ from slack_api.slack_conversations_history import ( SlackMessageSubtypeBotRemove, SlackMessageSubtypeChannelJoin, SlackMessageSubtypeChannelLeave, + SlackMessageSubtypeHuddleThread, + SlackMessageSubtypeHuddleThreadRoom, SlackMessageThreadParentNotSubscribed, SlackMessageThreadParentSubscribed, SlackMessageWithFiles, @@ -41,6 +43,11 @@ class SlackMessageWithFilesRtm(SlackMessageWithFiles): channel: str @final +class SlackMessageSubtypeHuddleThreadRtm(SlackMessageSubtypeHuddleThread): + event_ts: str + suppress_notification: bool + +@final class SlackMessageSubtypeBotMessageRtm(SlackMessageSubtypeBotMessage): channel: str @@ -118,6 +125,27 @@ class SlackReactionRemoved(TypedDict): event_ts: str ts: str +class SlackShRoomHuddle(TypedDict): + channel_id: str + +@final +class SlackShRoomJoin(TypedDict): + type: Literal["sh_room_join"] + room: SlackMessageSubtypeHuddleThreadRoom + user: str + huddle: SlackShRoomHuddle + event_ts: str + ts: str + +@final +class SlackShRoomUpdate(TypedDict): + type: Literal["sh_room_update"] + room: SlackMessageSubtypeHuddleThreadRoom + user: str + huddle: SlackShRoomHuddle + event_ts: str + ts: str + @final class SlackUserTyping(TypedDict): type: Literal["user_typing"] @@ -132,6 +160,7 @@ SlackMessageRtm = ( | SlackMessageThreadParentNotSubscribedRtm | SlackMessageThreadParentSubscribedRtm | SlackMessageWithFilesRtm + | SlackMessageSubtypeHuddleThreadRtm | SlackMessageSubtypeBotMessageRtm | SlackMessageSubtypeBotRemoveRtm | SlackMessageSubtypeBotAddRtm @@ -147,5 +176,7 @@ SlackRtmMessage = ( | SlackMessageReplied | SlackReactionAdded | SlackReactionRemoved + | SlackShRoomJoin + | SlackShRoomUpdate | SlackUserTyping ) |