|
5 | 5 |
|
6 | 6 | from slack_sdk.models import show_unknown_key_warning |
7 | 7 | from slack_sdk.models.basic_objects import JsonObject, JsonValidator |
| 8 | +from slack_sdk.models.messages.chunk import URLSource |
8 | 9 |
|
9 | 10 | from ...errors import SlackObjectFormationError |
10 | 11 | from .basic_components import MarkdownTextObject, PlainTextObject, SlackFile, TextObject |
@@ -97,6 +98,8 @@ def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]: |
97 | 98 | return RichTextBlock(**block) |
98 | 99 | elif type == TableBlock.type: |
99 | 100 | return TableBlock(**block) |
| 101 | + elif type == TaskCardBlock.type: |
| 102 | + return TaskCardBlock(**block) |
100 | 103 | else: |
101 | 104 | cls.logger.warning(f"Unknown block detected and skipped ({block})") |
102 | 105 | return None |
@@ -777,3 +780,46 @@ def __init__( |
777 | 780 | @JsonValidator("rows attribute must be specified") |
778 | 781 | def _validate_rows(self): |
779 | 782 | return self.rows is not None and len(self.rows) > 0 |
| 783 | + |
| 784 | + |
| 785 | +class TaskCardBlock(Block): |
| 786 | + type = "task_card" |
| 787 | + |
| 788 | + @property |
| 789 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 790 | + return super().attributes.union( |
| 791 | + { |
| 792 | + "task_id", |
| 793 | + "title", |
| 794 | + "details", |
| 795 | + "output", |
| 796 | + "sources", |
| 797 | + "status", |
| 798 | + } |
| 799 | + ) |
| 800 | + |
| 801 | + def __init__( |
| 802 | + self, |
| 803 | + *, |
| 804 | + task_id: str, |
| 805 | + title: str, |
| 806 | + details: Optional[Union[RichTextBlock, dict]] = None, |
| 807 | + output: Optional[Union[RichTextBlock, dict]] = None, |
| 808 | + sources: Optional[Sequence[Union[URLSource, dict]]] = None, |
| 809 | + status: str, # pending, in_progress, complete, error |
| 810 | + block_id: Optional[str] = None, |
| 811 | + **others: dict, |
| 812 | + ): |
| 813 | + super().__init__(type=self.type, block_id=block_id) |
| 814 | + show_unknown_key_warning(self, others) |
| 815 | + |
| 816 | + self.task_id = task_id |
| 817 | + self.title = title |
| 818 | + self.details = details |
| 819 | + self.output = output |
| 820 | + self.sources = sources |
| 821 | + self.status = status |
| 822 | + |
| 823 | + @JsonValidator("status must be an expected value (pending, in_progress, complete, or error)") |
| 824 | + def _validate_rows(self): |
| 825 | + return self.status in ["pending", "in_progress", "complete", "error"] |
0 commit comments