From 8257c27e40b5444cfe999942a5cb14a7498a5190 Mon Sep 17 00:00:00 2001 From: Jason Lingohr Date: Tue, 14 Jan 2025 08:41:35 +1100 Subject: [PATCH 1/2] Additional check for exceptions (#1632) Try to avoid internal exceptions from aiohttp in `message_data` --- slack_sdk/socket_mode/aiohttp/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slack_sdk/socket_mode/aiohttp/__init__.py b/slack_sdk/socket_mode/aiohttp/__init__.py index 3582a2ed..fb4bcb11 100644 --- a/slack_sdk/socket_mode/aiohttp/__init__.py +++ b/slack_sdk/socket_mode/aiohttp/__init__.py @@ -241,7 +241,7 @@ async def receive_messages(self) -> None: message_data = message.data if isinstance(message_data, bytes): message_data = message_data.decode("utf-8") - if message_data is not None and len(message_data) > 0: + if message_data is not None and isinstance(message_data, (str, bytes)) and len(message_data) > 0: # To skip the empty message that Slack server-side often sends self.logger.debug( f"Received message " From c9fff5d43abcec2ea1a19ac8d5a2efbd3732fb76 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Tue, 14 Jan 2025 23:53:36 +0900 Subject: [PATCH 2/2] Fix #1611 Add expand attribute to SectionBlock (#1635) --- slack_sdk/models/blocks/blocks.py | 8 +++++++- tests/slack_sdk/models/test_blocks.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/slack_sdk/models/blocks/blocks.py b/slack_sdk/models/blocks/blocks.py index 59ebac67..3b39af57 100644 --- a/slack_sdk/models/blocks/blocks.py +++ b/slack_sdk/models/blocks/blocks.py @@ -115,7 +115,7 @@ class SectionBlock(Block): @property def attributes(self) -> Set[str]: # type: ignore[override] - return super().attributes.union({"text", "fields", "accessory"}) + return super().attributes.union({"text", "fields", "accessory", "expand"}) def __init__( self, @@ -124,6 +124,7 @@ def __init__( text: Optional[Union[str, dict, TextObject]] = None, fields: Optional[Sequence[Union[str, dict, TextObject]]] = None, accessory: Optional[Union[dict, BlockElement]] = None, + expand: Optional[bool] = None, **others: dict, ): """A section is one of the most flexible blocks available. @@ -144,6 +145,10 @@ def __init__( in a compact format that allows for 2 columns of side-by-side text. Maximum number of items is 10. Maximum length for the text in each item is 2000 characters. accessory: One of the available element objects. + expand: Whether or not this section block's text should always expand when rendered. + If false or not provided, it may be rendered with a 'see more' option to expand and show the full text. + For AI Assistant apps, this allows the app to post long messages without users needing + to click 'see more' to expand the message. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) @@ -166,6 +171,7 @@ def __init__( self.logger.warning(f"Unsupported filed detected and skipped {f}") self.fields = field_objects self.accessory = BlockElement.parse(accessory) # type: ignore[arg-type] + self.expand = expand @JsonValidator("text or fields attribute must be specified") def _validate_text_or_fields_populated(self): diff --git a/tests/slack_sdk/models/test_blocks.py b/tests/slack_sdk/models/test_blocks.py index 940669b0..ade4bfe8 100644 --- a/tests/slack_sdk/models/test_blocks.py +++ b/tests/slack_sdk/models/test_blocks.py @@ -127,6 +127,18 @@ def test_parse(self): } self.assertDictEqual(input, SectionBlock(**input).to_dict()) + def test_parse_2(self): + input = { + "type": "section", + "text": { + "type": "plain_text", + "text": "This is a plain text section block.", + "emoji": True, + }, + "expand": True, + } + self.assertDictEqual(input, SectionBlock(**input).to_dict()) + def test_json(self): self.assertDictEqual( {