diff --git a/slack_sdk/models/blocks/block_elements.py b/slack_sdk/models/blocks/block_elements.py index 7b52b0f95..3ead7558c 100644 --- a/slack_sdk/models/blocks/block_elements.py +++ b/slack_sdk/models/blocks/block_elements.py @@ -2096,6 +2096,60 @@ def to_dict(self, *args) -> dict: } return {k: v for k, v in result.items() if v is not None} + class AttachmentMention(RichTextElement): + type = "attachment_mention" + + @property + def attributes(self) -> Set[str]: # type: ignore[override] + return super().attributes.union( + { + "url", + "text", + "app_id", + "entity_id", + "icon_url", + "channel_id", + "ts", + "full_size_preview_enabled", + "icon_name", + "reference_object_type", + "product_name", + "style", + } + ) + + def __init__( + self, + *, + url: str, + text: Optional[str] = None, + app_id: Optional[str] = None, + entity_id: Optional[str] = None, + icon_url: Optional[str] = None, + channel_id: Optional[str] = None, + ts: Optional[str] = None, + full_size_preview_enabled: Optional[bool] = None, + icon_name: Optional[str] = None, + reference_object_type: Optional[str] = None, + product_name: Optional[str] = None, + style: Optional[Union[dict, "RichTextElementParts.TextStyle"]] = None, + **others: dict, + ): + super().__init__(type=self.type) + show_unknown_key_warning(self, others) + self.url = url + self.text = text + self.app_id = app_id + self.entity_id = entity_id + self.icon_url = icon_url + self.channel_id = channel_id + self.ts = ts + self.full_size_preview_enabled = full_size_preview_enabled + self.icon_name = icon_name + self.reference_object_type = reference_object_type + self.product_name = product_name + self.style = style + class Text(RichTextElement): type = "text" diff --git a/tests/slack_sdk/models/test_elements.py b/tests/slack_sdk/models/test_elements.py index 4a5a062d3..e856dedb9 100644 --- a/tests/slack_sdk/models/test_elements.py +++ b/tests/slack_sdk/models/test_elements.py @@ -91,6 +91,35 @@ def test_with_input_interactive_element(self): self.assertDictEqual(input, InputInteractiveElement(**input).to_dict()) +class AttachmentMentionElementTests(unittest.TestCase): + def test_all_fields(self): + input = { + "type": "attachment_mention", + "url": "https://example.com/attachment", + "text": "Fallback text", + "app_id": "A0123456789", + "entity_id": "E0123456789", + "icon_url": "https://example.com/icon.png", + "channel_id": "C0123456789", + "ts": "1234567890.123456", + "full_size_preview_enabled": True, + "icon_name": "sf-account", + "reference_object_type": "record", + "product_name": "Salesforce", + "style": {"bold": True}, + } + self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict()) + + def test_document(self): + # Matches the docs reference example field-for-field: + # https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element + input = { + "type": "attachment_mention", + "url": "https://example.com/attachment", + } + self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict()) + + class ButtonElementTests(unittest.TestCase): def test_document_1(self): input = {