Skip to content

Commit 9d40cb0

Browse files
committed
feat: add task_card block
1 parent 92c93e0 commit 9d40cb0

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎slack_sdk/models/blocks/blocks.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from slack_sdk.models import show_unknown_key_warning
77
from slack_sdk.models.basic_objects import JsonObject, JsonValidator
8+
from slack_sdk.models.messages.chunk import URLSource
89

910
from ...errors import SlackObjectFormationError
1011
from .basic_components import MarkdownTextObject, PlainTextObject, SlackFile, TextObject
@@ -97,6 +98,8 @@ def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]:
9798
return RichTextBlock(**block)
9899
elif type == TableBlock.type:
99100
return TableBlock(**block)
101+
elif type == TaskCardBlock.type:
102+
return TaskCardBlock(**block)
100103
else:
101104
cls.logger.warning(f"Unknown block detected and skipped ({block})")
102105
return None
@@ -777,3 +780,46 @@ def __init__(
777780
@JsonValidator("rows attribute must be specified")
778781
def _validate_rows(self):
779782
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

Comments
 (0)