Skip to content
Draft
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
54 changes: 54 additions & 0 deletions slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
29 changes: 29 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading