diff --git a/block-kit/README.md b/block-kit/README.md index 1e1078a..5a474f5 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -29,6 +29,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes ### 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/elements/attachment_mention.py). - **[Broadcast](https://docs.slack.dev/reference/block-kit/block-elements/broadcast-element)**: Displays a broadcast mention such as here, channel, or everyone. [Implementation](./src/elements/broadcast.py). - **[Button](https://docs.slack.dev/reference/block-kit/block-elements/button-element)**: Allows users a direct path to performing basic actions. [Implementation](./src/elements/button.py). - **[Channel](https://docs.slack.dev/reference/block-kit/block-elements/channel-element)**: Renders as a mention of a channel. [Implementation](./src/elements/channel.py). diff --git a/block-kit/src/elements/attachment_mention.py b/block-kit/src/elements/attachment_mention.py new file mode 100644 index 0000000..203ff4e --- /dev/null +++ b/block-kit/src/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/elements/test_attachment_mention.py b/block-kit/tests/elements/test_attachment_mention.py new file mode 100644 index 0000000..b713931 --- /dev/null +++ b/block-kit/tests/elements/test_attachment_mention.py @@ -0,0 +1,23 @@ +import json + +from src.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)