Skip to content

Commit 22b5df2

Browse files
zimegClaude
andcommitted
feat(models): add AttachmentMention rich text element
Add a typed `RichTextElementParts.AttachmentMention` builder for the `attachment_mention` rich text element, which renders as a rich app attachment or entity reference within a `rich_text` block. Fields follow the reference documentation: https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element/ Adds `test_document` (the url-only payload shown in the docs) and `test_all_fields` (every optional field) asserting `to_dict()` output. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 49101ef commit 22b5df2

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

‎slack_sdk/models/blocks/block_elements.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,60 @@ def to_dict(self, *args) -> dict:
20962096
}
20972097
return {k: v for k, v in result.items() if v is not None}
20982098

2099+
class AttachmentMention(RichTextElement):
2100+
type = "attachment_mention"
2101+
2102+
@property
2103+
def attributes(self) -> Set[str]: # type: ignore[override]
2104+
return super().attributes.union(
2105+
{
2106+
"url",
2107+
"text",
2108+
"app_id",
2109+
"entity_id",
2110+
"icon_url",
2111+
"channel_id",
2112+
"ts",
2113+
"full_size_preview_enabled",
2114+
"icon_name",
2115+
"reference_object_type",
2116+
"product_name",
2117+
"style",
2118+
}
2119+
)
2120+
2121+
def __init__(
2122+
self,
2123+
*,
2124+
url: str,
2125+
text: Optional[str] = None,
2126+
app_id: Optional[str] = None,
2127+
entity_id: Optional[str] = None,
2128+
icon_url: Optional[str] = None,
2129+
channel_id: Optional[str] = None,
2130+
ts: Optional[str] = None,
2131+
full_size_preview_enabled: Optional[bool] = None,
2132+
icon_name: Optional[str] = None,
2133+
reference_object_type: Optional[str] = None,
2134+
product_name: Optional[str] = None,
2135+
style: Optional[Union[dict, "RichTextElementParts.TextStyle"]] = None,
2136+
**others: dict,
2137+
):
2138+
super().__init__(type=self.type)
2139+
show_unknown_key_warning(self, others)
2140+
self.url = url
2141+
self.text = text
2142+
self.app_id = app_id
2143+
self.entity_id = entity_id
2144+
self.icon_url = icon_url
2145+
self.channel_id = channel_id
2146+
self.ts = ts
2147+
self.full_size_preview_enabled = full_size_preview_enabled
2148+
self.icon_name = icon_name
2149+
self.reference_object_type = reference_object_type
2150+
self.product_name = product_name
2151+
self.style = style
2152+
20992153
class Text(RichTextElement):
21002154
type = "text"
21012155

‎tests/slack_sdk/models/test_elements.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,3 +1439,37 @@ def test_load(self):
14391439
},
14401440
}
14411441
self.assertDictEqual(input, WorkflowButtonElement(**input).to_dict())
1442+
1443+
1444+
# -------------------------------------------------
1445+
# Attachment Mention (rich text element)
1446+
# -------------------------------------------------
1447+
1448+
1449+
class AttachmentMentionElementTests(unittest.TestCase):
1450+
def test_all_fields(self):
1451+
input = {
1452+
"type": "attachment_mention",
1453+
"url": "https://example.com/attachment",
1454+
"text": "Fallback text",
1455+
"app_id": "A0123456789",
1456+
"entity_id": "E0123456789",
1457+
"icon_url": "https://example.com/icon.png",
1458+
"channel_id": "C0123456789",
1459+
"ts": "1234567890.123456",
1460+
"full_size_preview_enabled": True,
1461+
"icon_name": "sf-account",
1462+
"reference_object_type": "record",
1463+
"product_name": "Salesforce",
1464+
"style": {"bold": True},
1465+
}
1466+
self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict())
1467+
1468+
def test_document(self):
1469+
# Matches the docs reference example field-for-field:
1470+
# https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element
1471+
input = {
1472+
"type": "attachment_mention",
1473+
"url": "https://example.com/attachment",
1474+
}
1475+
self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict())

0 commit comments

Comments
 (0)