From 3d93791f0dbcb1923ebeb3af485f022c30a72e27 Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Thu, 27 Aug 2026 16:30:10 -0400 Subject: [PATCH 1/3] feat: add card block example --- block-kit/src/blocks/card.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 block-kit/src/blocks/card.py diff --git a/block-kit/src/blocks/card.py b/block-kit/src/blocks/card.py new file mode 100644 index 0000000..3763bd1 --- /dev/null +++ b/block-kit/src/blocks/card.py @@ -0,0 +1,28 @@ +from slack_sdk.models.blocks import CardBlock +from slack_sdk.models.blocks.basic_components import MarkdownTextObject, PlainTextObject +from slack_sdk.models.blocks.block_elements import ButtonElement, ImageElement + + +def example01() -> CardBlock: + """ + Displays content in a card layout with optional icon, title, body, and actions. + https://docs.slack.dev/reference/block-kit/blocks/card-block/ + + A card with icon, title, subtitle, hero image, body, and an action button. + """ + block = CardBlock( + icon=ImageElement(image_url="https://picsum.photos/36/36", alt_text="Icon"), + title=MarkdownTextObject(text="Lumon Industries"), + subtitle=MarkdownTextObject(text="Committed to work-life balance"), + hero_image=ImageElement( + image_url="https://picsum.photos/400/300", alt_text="Sample hero image" + ), + body=MarkdownTextObject(text="Please enjoy each card equally."), + actions=[ + ButtonElement( + text=PlainTextObject(text="Action Button", emoji=False), + action_id="button_action", + ), + ], + ) + return block From 1cfe8c527fa1c763068ca1b4a57bfe471b961c40 Mon Sep 17 00:00:00 2001 From: Ale Mercado <104795114+srtaalej@users.noreply.github.com> Date: Fri, 28 Aug 2026 10:02:43 -0400 Subject: [PATCH 2/3] Update block-kit/src/blocks/card.py Co-authored-by: Eden Zimbelman --- block-kit/src/blocks/card.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block-kit/src/blocks/card.py b/block-kit/src/blocks/card.py index 3763bd1..23adef4 100644 --- a/block-kit/src/blocks/card.py +++ b/block-kit/src/blocks/card.py @@ -5,7 +5,7 @@ def example01() -> CardBlock: """ - Displays content in a card layout with optional icon, title, body, and actions. + Displays content in a card. https://docs.slack.dev/reference/block-kit/blocks/card-block/ A card with icon, title, subtitle, hero image, body, and an action button. From 858631a6d49304d0f173a0a8d2c5b01f246606c1 Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Fri, 28 Aug 2026 10:20:58 -0400 Subject: [PATCH 3/3] feat: add test and readme entry for card block example --- block-kit/README.md | 1 + block-kit/tests/blocks/test_card.py | 45 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 block-kit/tests/blocks/test_card.py diff --git a/block-kit/README.md b/block-kit/README.md index 9785597..318d357 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -10,6 +10,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py). - **[Alert](https://docs.slack.dev/reference/block-kit/blocks/alert-block)**: Displays alerts, warnings, and informational messages. [Implementation](./src/blocks/alert.py). +- **[Card](https://docs.slack.dev/reference/block-kit/blocks/card-block)**: Displays content in a card. [Implementation](./src/blocks/card.py). - **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/blocks/context.py). - **[Context actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Displays actions as contextual info, which can include both feedback buttons and icon buttons. [Implementation](./src/blocks/context_actions.py). - **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/blocks/divider.py). diff --git a/block-kit/tests/blocks/test_card.py b/block-kit/tests/blocks/test_card.py new file mode 100644 index 0000000..17a6e31 --- /dev/null +++ b/block-kit/tests/blocks/test_card.py @@ -0,0 +1,45 @@ +import json + +from src.blocks import card + + +def test_example01(): + block = card.example01() + actual = block.to_dict() + expected = { + "type": "card", + "icon": { + "type": "image", + "image_url": "https://picsum.photos/36/36", + "alt_text": "Icon", + }, + "title": { + "type": "mrkdwn", + "text": "Lumon Industries", + }, + "subtitle": { + "type": "mrkdwn", + "text": "Committed to work-life balance", + }, + "hero_image": { + "type": "image", + "image_url": "https://picsum.photos/400/300", + "alt_text": "Sample hero image", + }, + "body": { + "type": "mrkdwn", + "text": "Please enjoy each card equally.", + }, + "actions": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action Button", + "emoji": False, + }, + "action_id": "button_action", + }, + ], + } + assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)