Skip to content

Commit 03dcfc6

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 03dcfc6

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
@@ -2297,3 +2297,57 @@ def __init__(
22972297
show_unknown_key_warning(self, others)
22982298
self.value = value
22992299
self.style = style
2300+
2301+
class AttachmentMention(RichTextElement):
2302+
type = "attachment_mention"
2303+
2304+
@property
2305+
def attributes(self) -> Set[str]: # type: ignore[override]
2306+
return super().attributes.union(
2307+
{
2308+
"url",
2309+
"text",
2310+
"app_id",
2311+
"entity_id",
2312+
"icon_url",
2313+
"channel_id",
2314+
"ts",
2315+
"full_size_preview_enabled",
2316+
"icon_name",
2317+
"reference_object_type",
2318+
"product_name",
2319+
"style",
2320+
}
2321+
)
2322+
2323+
def __init__(
2324+
self,
2325+
*,
2326+
url: str,
2327+
text: Optional[str] = None,
2328+
app_id: Optional[str] = None,
2329+
entity_id: Optional[str] = None,
2330+
icon_url: Optional[str] = None,
2331+
channel_id: Optional[str] = None,
2332+
ts: Optional[str] = None,
2333+
full_size_preview_enabled: Optional[bool] = None,
2334+
icon_name: Optional[str] = None,
2335+
reference_object_type: Optional[str] = None,
2336+
product_name: Optional[str] = None,
2337+
style: Optional[Union[dict, "RichTextElementParts.TextStyle"]] = None,
2338+
**others: dict,
2339+
):
2340+
super().__init__(type=self.type)
2341+
show_unknown_key_warning(self, others)
2342+
self.url = url
2343+
self.text = text
2344+
self.app_id = app_id
2345+
self.entity_id = entity_id
2346+
self.icon_url = icon_url
2347+
self.channel_id = channel_id
2348+
self.ts = ts
2349+
self.full_size_preview_enabled = full_size_preview_enabled
2350+
self.icon_name = icon_name
2351+
self.reference_object_type = reference_object_type
2352+
self.product_name = product_name
2353+
self.style = style

‎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_document(self):
1451+
# Matches the docs reference example field-for-field:
1452+
# https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element
1453+
input = {
1454+
"type": "attachment_mention",
1455+
"url": "https://example.com/attachment",
1456+
}
1457+
self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict())
1458+
1459+
def test_all_fields(self):
1460+
input = {
1461+
"type": "attachment_mention",
1462+
"url": "https://example.com/attachment",
1463+
"text": "Fallback text",
1464+
"app_id": "A0123456789",
1465+
"entity_id": "E0123456789",
1466+
"icon_url": "https://example.com/icon.png",
1467+
"channel_id": "C0123456789",
1468+
"ts": "1234567890.123456",
1469+
"full_size_preview_enabled": True,
1470+
"icon_name": "sf-account",
1471+
"reference_object_type": "record",
1472+
"product_name": "Salesforce",
1473+
"style": {"bold": True},
1474+
}
1475+
self.assertDictEqual(input, RichTextElementParts.AttachmentMention(**input).to_dict())

0 commit comments

Comments
 (0)