|
16 | 16 | InputInteractiveElement, |
17 | 17 | InteractiveElement, |
18 | 18 | RichTextElement, |
| 19 | + UrlSourceElement, |
19 | 20 | ) |
20 | 21 |
|
21 | 22 | # ------------------------------------------------- |
@@ -97,6 +98,10 @@ 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) |
| 103 | + elif type == PlanBlock.type: |
| 104 | + return PlanBlock(**block) |
100 | 105 | else: |
101 | 106 | cls.logger.warning(f"Unknown block detected and skipped ({block})") |
102 | 107 | return None |
@@ -777,3 +782,104 @@ def __init__( |
777 | 782 | @JsonValidator("rows attribute must be specified") |
778 | 783 | def _validate_rows(self): |
779 | 784 | return self.rows is not None and len(self.rows) > 0 |
| 785 | + |
| 786 | + |
| 787 | +class TaskCardBlock(Block): |
| 788 | + type = "task_card" |
| 789 | + |
| 790 | + @property |
| 791 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 792 | + return super().attributes.union( |
| 793 | + { |
| 794 | + "task_id", |
| 795 | + "title", |
| 796 | + "details", |
| 797 | + "output", |
| 798 | + "sources", |
| 799 | + "status", |
| 800 | + } |
| 801 | + ) |
| 802 | + |
| 803 | + def __init__( |
| 804 | + self, |
| 805 | + *, |
| 806 | + task_id: str, |
| 807 | + title: str, |
| 808 | + details: Optional[Union[RichTextBlock, dict]] = None, |
| 809 | + output: Optional[Union[RichTextBlock, dict]] = None, |
| 810 | + sources: Optional[Sequence[Union[UrlSourceElement, dict]]] = None, |
| 811 | + status: str, # pending, in_progress, complete, error |
| 812 | + block_id: Optional[str] = None, |
| 813 | + **others: dict, |
| 814 | + ): |
| 815 | + """A discrete action or tool call. |
| 816 | + https://docs.slack.dev/reference/block-kit/blocks/task-card-block/ |
| 817 | +
|
| 818 | + Args: |
| 819 | + block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. |
| 820 | + Maximum length for this field is 255 characters. |
| 821 | + block_id should be unique for each message and each iteration of a message. |
| 822 | + If a message is updated, use a new block_id. |
| 823 | + task_id (required): ID for the task |
| 824 | + title (required): Title of the task in plain text |
| 825 | + details: Details of the task in the form of a single "rich_text" entity. |
| 826 | + output: Output of the task in the form of a single "rich_text" entity. |
| 827 | + sources: List of sources used to generate a response |
| 828 | + status: The state of a task. Either "pending" or "in_progress" or "complete" or "error". |
| 829 | + """ |
| 830 | + super().__init__(type=self.type, block_id=block_id) |
| 831 | + show_unknown_key_warning(self, others) |
| 832 | + |
| 833 | + self.task_id = task_id |
| 834 | + self.title = title |
| 835 | + self.details = details |
| 836 | + self.output = output |
| 837 | + self.sources = sources |
| 838 | + self.status = status |
| 839 | + |
| 840 | + @JsonValidator("status must be an expected value (pending, in_progress, complete, or error)") |
| 841 | + def _validate_rows(self): |
| 842 | + return self.status in ["pending", "in_progress", "complete", "error"] |
| 843 | + |
| 844 | + |
| 845 | +class PlanBlock(Block): |
| 846 | + type = "plan" |
| 847 | + |
| 848 | + @property |
| 849 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 850 | + return super().attributes.union( |
| 851 | + { |
| 852 | + "plan_id", |
| 853 | + "title", |
| 854 | + "tasks", |
| 855 | + } |
| 856 | + ) |
| 857 | + |
| 858 | + def __init__( |
| 859 | + self, |
| 860 | + *, |
| 861 | + plan_id: str, |
| 862 | + title: str, |
| 863 | + tasks: Optional[Sequence[Union[Dict, TaskCardBlock]]] = None, |
| 864 | + block_id: Optional[str] = None, |
| 865 | + **others: dict, |
| 866 | + ): |
| 867 | + """A collection of related tasks. |
| 868 | + https://docs.slack.dev/reference/block-kit/blocks/plan-block/ |
| 869 | +
|
| 870 | + Args: |
| 871 | + block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. |
| 872 | + Maximum length for this field is 255 characters. |
| 873 | + block_id should be unique for each message and each iteration of a message. |
| 874 | + If a message is updated, use a new block_id. |
| 875 | + plan_id (required): ID for the plan (May be removed / made optional, feel free to pass in a random UUID |
| 876 | + for now) |
| 877 | + title (required): Title of the plan in plain text |
| 878 | + tasks: Details of the task in the form of a single "rich_text" entity. |
| 879 | + """ |
| 880 | + super().__init__(type=self.type, block_id=block_id) |
| 881 | + show_unknown_key_warning(self, others) |
| 882 | + |
| 883 | + self.plan_id = plan_id |
| 884 | + self.title = title |
| 885 | + self.tasks = tasks |
0 commit comments