From c07ec79e0f6abd9277d5e536118d5faee673341a Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Thu, 27 Aug 2026 20:31:42 -0700 Subject: [PATCH] Add the attachment_mention block element example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Splits Block Kit element examples into their own `src/block_elements/` path (mirroring the docs' block-elements reference section) and adds the first one: `attachment_mention`, which renders as a rich app attachment or entity reference within a rich_text block. https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element/ The example uses the typed `RichTextElementParts.AttachmentMention` builder from python-slack-sdk#1948. That builder is not yet released, so this example's test/typecheck fail against the pinned slack_sdk until it ships — the example intentionally asserts the expected released shape so reviewers can test the builder PR against it. Co-Authored-By: Claude --- block-kit/README.md | 4 +++ block-kit/src/block_elements/__init__.py | 0 .../src/block_elements/attachment_mention.py | 26 +++++++++++++++++++ block-kit/tests/block_elements/__init__.py | 0 .../block_elements/test_attachment_mention.py | 23 ++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 block-kit/src/block_elements/__init__.py create mode 100644 block-kit/src/block_elements/attachment_mention.py create mode 100644 block-kit/tests/block_elements/__init__.py create mode 100644 block-kit/tests/block_elements/test_attachment_mention.py diff --git a/block-kit/README.md b/block-kit/README.md index 9785597..5e5f055 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -24,3 +24,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Table](https://docs.slack.dev/reference/block-kit/blocks/table-block)**: Displays structured information in a table. [Implementation](./src/blocks/table.py). - **[Task card](https://docs.slack.dev/reference/block-kit/blocks/task-card-block)**: Displays a single task, representing a single action. [Implementation](./src/blocks/task_card.py). - **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.py). + +### Block elements + +- **[Attachment mention](https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element)**: Renders as a rich app attachment or entity reference. [Implementation](./src/block_elements/attachment_mention.py). diff --git a/block-kit/src/block_elements/__init__.py b/block-kit/src/block_elements/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/block-kit/src/block_elements/attachment_mention.py b/block-kit/src/block_elements/attachment_mention.py new file mode 100644 index 0000000..2741014 --- /dev/null +++ b/block-kit/src/block_elements/attachment_mention.py @@ -0,0 +1,26 @@ +from slack_sdk.models.blocks import RichTextBlock +from slack_sdk.models.blocks.block_elements import ( + RichTextElementParts, + RichTextSectionElement, +) + + +def example01() -> RichTextBlock: + """ + Renders as a rich app attachment or entity reference. + https://docs.slack.dev/reference/block-kit/block-elements/attachment-mention-element/ + + An attachment mention referencing an app attachment by URL. + """ + block = RichTextBlock( + elements=[ + RichTextSectionElement( + elements=[ + RichTextElementParts.AttachmentMention( + url="https://example.com/attachment" + ) + ] + ) + ] + ) + return block diff --git a/block-kit/tests/block_elements/__init__.py b/block-kit/tests/block_elements/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/block-kit/tests/block_elements/test_attachment_mention.py b/block-kit/tests/block_elements/test_attachment_mention.py new file mode 100644 index 0000000..c70e5e9 --- /dev/null +++ b/block-kit/tests/block_elements/test_attachment_mention.py @@ -0,0 +1,23 @@ +import json + +from src.block_elements import attachment_mention + + +def test_example01(): + block = attachment_mention.example01() + actual = block.to_dict() + expected = { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "attachment_mention", + "url": "https://example.com/attachment", + } + ], + } + ], + } + assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)