Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1611 Add expand attribute to SectionBlock #1635

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading