| 63 | |
| 64 | @classmethod |
| 65 | def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]: |
| 66 | if block is None: |
| 67 | return None |
| 68 | elif isinstance(block, Block): |
| 69 | return block |
| 70 | else: |
| 71 | if "type" in block: |
| 72 | type = block["type"] |
| 73 | if type == SectionBlock.type: |
| 74 | return SectionBlock(**block) |
| 75 | elif type == DividerBlock.type: |
| 76 | return DividerBlock(**block) |
| 77 | elif type == ImageBlock.type: |
| 78 | return ImageBlock(**block) |
| 79 | elif type == ActionsBlock.type: |
| 80 | return ActionsBlock(**block) |
| 81 | elif type == ContextBlock.type: |
| 82 | return ContextBlock(**block) |
| 83 | elif type == ContextActionsBlock.type: |
| 84 | return ContextActionsBlock(**block) |
| 85 | elif type == InputBlock.type: |
| 86 | return InputBlock(**block) |
| 87 | elif type == FileBlock.type: |
| 88 | return FileBlock(**block) |
| 89 | elif type == CallBlock.type: |
| 90 | return CallBlock(**block) |
| 91 | elif type == HeaderBlock.type: |
| 92 | return HeaderBlock(**block) |
| 93 | elif type == MarkdownBlock.type: |
| 94 | return MarkdownBlock(**block) |
| 95 | elif type == VideoBlock.type: |
| 96 | return VideoBlock(**block) |
| 97 | elif type == RichTextBlock.type: |
| 98 | return RichTextBlock(**block) |
| 99 | elif type == TableBlock.type: |
| 100 | return TableBlock(**block) |
| 101 | elif type == TaskCardBlock.type: |
| 102 | return TaskCardBlock(**block) |
| 103 | elif type == PlanBlock.type: |
| 104 | return PlanBlock(**block) |
| 105 | elif type == CardBlock.type: |
| 106 | return CardBlock(**block) |
| 107 | elif type == AlertBlock.type: |
| 108 | return AlertBlock(**block) |
| 109 | elif type == CarouselBlock.type: |
| 110 | return CarouselBlock(**block) |
| 111 | else: |
| 112 | cls.logger.warning(f"Unknown block detected and skipped ({block})") |
| 113 | return None |
| 114 | else: |
| 115 | cls.logger.warning(f"Unknown block detected and skipped ({block})") |
| 116 | return None |
| 117 | |
| 118 | @classmethod |
| 119 | def parse_all(cls, blocks: Optional[Sequence[Union[dict, "Block"]]]) -> List["Block"]: |