diff --git a/slack_sdk/models/blocks/block_elements.py b/slack_sdk/models/blocks/block_elements.py index 8977001e..46ab75da 100644 --- a/slack_sdk/models/blocks/block_elements.py +++ b/slack_sdk/models/blocks/block_elements.py @@ -1868,7 +1868,7 @@ def __init__( ): super().__init__(type=self.type) show_unknown_key_warning(self, others) - self.elements = elements + self.elements = BlockElement.parse_all(elements) self.style = style self.indent = indent self.offset = offset @@ -1891,7 +1891,7 @@ def __init__( ): super().__init__(type=self.type) show_unknown_key_warning(self, others) - self.elements = elements + self.elements = BlockElement.parse_all(elements) self.border = border @@ -1910,7 +1910,7 @@ def __init__( ): super().__init__(type=self.type) show_unknown_key_warning(self, others) - self.elements = elements + self.elements = BlockElement.parse_all(elements) class RichTextSectionElement(RichTextElement): @@ -1928,7 +1928,7 @@ def __init__( ): super().__init__(type=self.type) show_unknown_key_warning(self, others) - self.elements = elements + self.elements = BlockElement.parse_all(elements) class RichTextElementParts: diff --git a/tests/slack_sdk/models/test_blocks.py b/tests/slack_sdk/models/test_blocks.py index 92abc761..66b17d2a 100644 --- a/tests/slack_sdk/models/test_blocks.py +++ b/tests/slack_sdk/models/test_blocks.py @@ -1083,3 +1083,38 @@ def test_complex(self): ], ) self.assertDictEqual(dict_block, class_block.to_dict()) + + def test_elements_are_parsed(self): + dict_block = { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [{"type": "text", "text": "Hello there, I am a basic rich text block!"}], + }, + { + "type": "rich_text_quote", + "elements": [{"type": "text", "text": "this is very important"}], + }, + { + "type": "rich_text_preformatted", + "elements": [{"type": "text", "text": 'print("Hello world")'}], + }, + { + "type": "rich_text_list", + "elements": [ + {"type": "rich_text_section", "elements": [{"type": "text", "text": "a"}]}, + ], + }, + ], + } + block = RichTextBlock(**dict_block) + self.assertIsInstance(block.elements[0], RichTextSectionElement) + self.assertIsInstance(block.elements[0].elements[0], RichTextElementParts.Text) + self.assertIsInstance(block.elements[1], RichTextQuoteElement) + self.assertIsInstance(block.elements[1].elements[0], RichTextElementParts.Text) + self.assertIsInstance(block.elements[2], RichTextPreformattedElement) + self.assertIsInstance(block.elements[2].elements[0], RichTextElementParts.Text) + self.assertIsInstance(block.elements[3], RichTextListElement) + self.assertIsInstance(block.elements[3].elements[0], RichTextSectionElement) + self.assertIsInstance(block.elements[3].elements[0].elements[0], RichTextElementParts.Text)