| 126 | |
| 127 | |
| 128 | class SectionBlock(Block): |
| 129 | type = "section" |
| 130 | fields_max_length = 10 |
| 131 | text_max_length = 3000 |
| 132 | |
| 133 | @property |
| 134 | def attributes(self) -> Set[str]: # type: ignore[override] |
| 135 | return super().attributes.union({"text", "fields", "accessory", "expand"}) |
| 136 | |
| 137 | def __init__( |
| 138 | self, |
| 139 | *, |
| 140 | block_id: Optional[str] = None, |
| 141 | text: Optional[Union[str, dict, TextObject]] = None, |
| 142 | fields: Optional[Sequence[Union[str, dict, TextObject]]] = None, |
| 143 | accessory: Optional[Union[dict, BlockElement]] = None, |
| 144 | expand: Optional[bool] = None, |
| 145 | **others: dict, |
| 146 | ): |
| 147 | """A section is one of the most flexible blocks available. |
| 148 | https://docs.slack.dev/reference/block-kit/blocks/section-block |
| 149 | |
| 150 | Args: |
| 151 | block_id (required): A string acting as a unique identifier for a block. |
| 152 | If not specified, one will be generated. |
| 153 | You can use this block_id when you receive an interaction payload to identify the source of the action. |
| 154 | Maximum length for this field is 255 characters. |
| 155 | block_id should be unique for each message and each iteration of a message. |
| 156 | If a message is updated, use a new block_id. |
| 157 | text (preferred): The text for the block, in the form of a text object. |
| 158 | Maximum length for the text in this field is 3000 characters. |
| 159 | This field is not required if a valid array of fields objects is provided instead. |
| 160 | fields (required if no text is provided): Required if no text is provided. |
| 161 | An array of text objects. Any text objects included with fields will be rendered |
| 162 | in a compact format that allows for 2 columns of side-by-side text. |
| 163 | Maximum number of items is 10. Maximum length for the text in each item is 2000 characters. |
| 164 | accessory: One of the available element objects. |
| 165 | expand: Whether or not this section block's text should always expand when rendered. |
| 166 | If false or not provided, it may be rendered with a 'see more' option to expand and show the full text. |
| 167 | For AI Assistant apps, this allows the app to post long messages without users needing |
| 168 | to click 'see more' to expand the message. |
| 169 | """ |
| 170 | super().__init__(type=self.type, block_id=block_id) |
| 171 | show_unknown_key_warning(self, others) |
| 172 | |
| 173 | self.text = TextObject.parse(text) # type: ignore[arg-type] |
| 174 | field_objects = [] |
| 175 | for f in fields or []: |
| 176 | if isinstance(f, str): |
| 177 | field_objects.append(MarkdownTextObject.from_str(f)) |
| 178 | elif isinstance(f, TextObject): |
| 179 | field_objects.append(f) # type: ignore[arg-type] |
| 180 | elif isinstance(f, dict) and "type" in f: |
| 181 | d = copy.copy(f) |
| 182 | t = d.pop("type") |
| 183 | if t == MarkdownTextObject.type: |
| 184 | field_objects.append(MarkdownTextObject(**d)) |
| 185 | else: |
no outgoing calls