Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions slack_sdk/models/blocks/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ def __init__(
self,
*,
block_id: Optional[str] = None,
hero_image: Optional[str] = None,
icon: Optional[str] = None,
Comment on lines -952 to -953
hero_image: Optional[Union[dict, ImageElement]] = None,
icon: Optional[Union[dict, ImageElement]] = None,
title: Optional[Union[str, dict, TextObject]] = None,
subtitle: Optional[Union[str, dict, TextObject]] = None,
body: Optional[Union[str, dict, TextObject]] = None,
Expand All @@ -962,8 +962,10 @@ def __init__(

Args:
block_id: A unique identifier for a block. If not specified, a block_id will be generated.
hero_image: Link to the top image used on the card.
icon: Link to the small image used next to the card's title and subtitle.
hero_image: Link to the top image used on the card. Max length 3000 characters.
The alt_text property has a max length of 2000 characters.
icon: Link to the small image used next to the card's title and subtitle. Max length
3000 characters. The alt_text property has a max length of 2000 characters.
title: Title of the card. 150 characters max.
subtitle: Subtitle of the card. 150 characters max.
body: Content of the card. 200 characters max.
Expand Down
28 changes: 25 additions & 3 deletions tests/slack_sdk/models/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
VideoBlock,
)
from slack_sdk.models.blocks.basic_components import FeedbackButtonObject, SlackFile
from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement
from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement, ImageElement

from . import STRING_3001_CHARS

Expand Down Expand Up @@ -1560,10 +1560,14 @@ class CardBlockTests(unittest.TestCase):
def test_document(self):
input = {
"type": "card",
"icon": "https://picsum.photos/36/36",
"icon": {"type": "image", "image_url": "https://picsum.photos/36/36", "alt_text": "Icon"},
"title": {"type": "mrkdwn", "text": "Lumon Industries", "verbatim": False},
"subtitle": {"type": "mrkdwn", "text": "Committed to work-life balance", "verbatim": False},
"hero_image": "https://picsum.photos/400/300",
"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.", "verbatim": False},
"actions": [
{
Expand All @@ -1575,6 +1579,24 @@ def test_document(self):
}
self.assertDictEqual(input, CardBlock(**input).to_dict())

def test_image_element_icon_and_hero_image(self):
block = CardBlock(
icon=ImageElement(image_url="https://picsum.photos/36/36", alt_text="Icon"),
hero_image=ImageElement(image_url="https://picsum.photos/400/300", alt_text="Sample hero image"),
title=MarkdownTextObject(text="Lumon Industries"),
)
expected = {
"type": "card",
"icon": {"type": "image", "image_url": "https://picsum.photos/36/36", "alt_text": "Icon"},
"hero_image": {
"type": "image",
"image_url": "https://picsum.photos/400/300",
"alt_text": "Sample hero image",
},
"title": {"type": "mrkdwn", "text": "Lumon Industries"},
}
self.assertDictEqual(expected, block.to_dict())

def test_parse(self):
input = {
"type": "card",
Expand Down
Loading