| 540 | |
| 541 | |
| 542 | class HeaderBlock(Block): |
| 543 | type = "header" |
| 544 | text_max_length = 150 |
| 545 | |
| 546 | @property |
| 547 | def attributes(self) -> Set[str]: # type: ignore[override] |
| 548 | return super().attributes.union({"text"}) |
| 549 | |
| 550 | def __init__( |
| 551 | self, |
| 552 | *, |
| 553 | block_id: Optional[str] = None, |
| 554 | text: Optional[Union[str, dict, TextObject]] = None, |
| 555 | **others: dict, |
| 556 | ): |
| 557 | """A header is a plain-text block that displays in a larger, bold font. |
| 558 | https://docs.slack.dev/reference/block-kit/blocks/header-block |
| 559 | |
| 560 | Args: |
| 561 | block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. |
| 562 | Maximum length for this field is 255 characters. |
| 563 | block_id should be unique for each message and each iteration of a message. |
| 564 | If a message is updated, use a new block_id. |
| 565 | text (required): The text for the block, in the form of a plain_text text object. |
| 566 | Maximum length for the text in this field is 150 characters. |
| 567 | """ |
| 568 | super().__init__(type=self.type, block_id=block_id) |
| 569 | show_unknown_key_warning(self, others) |
| 570 | |
| 571 | self.text = TextObject.parse(text, default_type=PlainTextObject.type) # type: ignore[arg-type] |
| 572 | |
| 573 | @JsonValidator("text attribute must be specified") |
| 574 | def _validate_text(self): |
| 575 | return self.text is not None |
| 576 | |
| 577 | @JsonValidator(f"text attribute cannot exceed {text_max_length} characters") |
| 578 | def _validate_alt_text_length(self): |
| 579 | return self.text is None or len(self.text.text) <= self.text_max_length |
| 580 | |
| 581 | |
| 582 | class MarkdownBlock(Block): |
no outgoing calls