Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions slack_sdk/models/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
RichTextBlock,
SectionBlock,
TableBlock,
TaskCardBlock,
VideoBlock,
)

Expand Down Expand Up @@ -137,6 +138,7 @@
"MarkdownBlock",
"SectionBlock",
"TableBlock",
"TaskCardBlock",
"VideoBlock",
"RichTextBlock",
]
46 changes: 46 additions & 0 deletions slack_sdk/models/blocks/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from slack_sdk.models import show_unknown_key_warning
from slack_sdk.models.basic_objects import JsonObject, JsonValidator
from slack_sdk.models.messages.chunk import URLSource
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 thought: This is introduced in #1806 but I'm not certain if it's best kept with the "messages" model or if it should be included as a block element?


from ...errors import SlackObjectFormationError
from .basic_components import MarkdownTextObject, PlainTextObject, SlackFile, TextObject
Expand Down Expand Up @@ -97,6 +98,8 @@ def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]:
return RichTextBlock(**block)
elif type == TableBlock.type:
return TableBlock(**block)
elif type == TaskCardBlock.type:
return TaskCardBlock(**block)
else:
cls.logger.warning(f"Unknown block detected and skipped ({block})")
return None
Expand Down Expand Up @@ -777,3 +780,46 @@ def __init__(
@JsonValidator("rows attribute must be specified")
def _validate_rows(self):
return self.rows is not None and len(self.rows) > 0


class TaskCardBlock(Block):
type = "task_card"

@property
def attributes(self) -> Set[str]: # type: ignore[override]
return super().attributes.union(
{
"task_id",
"title",
"details",
"output",
"sources",
"status",
}
)

def __init__(
self,
*,
task_id: str,
title: str,
details: Optional[Union[RichTextBlock, dict]] = None,
output: Optional[Union[RichTextBlock, dict]] = None,
sources: Optional[Sequence[Union[URLSource, dict]]] = None,
status: str, # pending, in_progress, complete, error
block_id: Optional[str] = None,
**others: dict,
):
super().__init__(type=self.type, block_id=block_id)
show_unknown_key_warning(self, others)

self.task_id = task_id
self.title = title
self.details = details
self.output = output
self.sources = sources
self.status = status

@JsonValidator("status must be an expected value (pending, in_progress, complete, or error)")
def _validate_rows(self):
return self.status in ["pending", "in_progress", "complete", "error"]