diff --git a/slack_sdk/models/blocks/blocks.py b/slack_sdk/models/blocks/blocks.py index db4de1f3a..46ed040a2 100644 --- a/slack_sdk/models/blocks/blocks.py +++ b/slack_sdk/models/blocks/blocks.py @@ -949,8 +949,8 @@ def __init__( self, *, block_id: Optional[str] = None, - hero_image: Optional[str] = None, - icon: Optional[str] = None, + 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, @@ -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. diff --git a/tests/slack_sdk/models/test_blocks.py b/tests/slack_sdk/models/test_blocks.py index fc9ff3266..ba0d378b1 100644 --- a/tests/slack_sdk/models/test_blocks.py +++ b/tests/slack_sdk/models/test_blocks.py @@ -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 @@ -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": [ { @@ -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",