Skip to content

Commit

Permalink
Fix #1611 Add expand attribute to SectionBlock (#1635)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Jan 14, 2025
1 parent 8257c27 commit c9fff5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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
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 c9fff5d

Please sign in to comment.