Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/slackapi/python-slack-sdk i…
Browse files Browse the repository at this point in the history
…nto feature/async-sqlalchemy
  • Loading branch information
galuszkak committed Jan 16, 2025
2 parents dc96064 + c9fff5d commit b3b221c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion slack_sdk/models/blocks/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion slack_sdk/socket_mode/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
12 changes: 12 additions & 0 deletions tests/slack_sdk/models/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down

0 comments on commit b3b221c

Please sign in to comment.