diff --git a/slack_sdk/models/messages/chunk.py b/slack_sdk/models/messages/chunk.py index 837714af..5f225bdc 100644 --- a/slack_sdk/models/messages/chunk.py +++ b/slack_sdk/models/messages/chunk.py @@ -34,6 +34,8 @@ def parse(cls, chunk: Union[Dict, "Chunk"]) -> Optional["Chunk"]: type = chunk["type"] if type == MarkdownTextChunk.type: return MarkdownTextChunk(**chunk) + elif type == PlanUpdateChunk.type: + return PlanUpdateChunk(**chunk) elif type == TaskUpdateChunk.type: return TaskUpdateChunk(**chunk) else: @@ -67,6 +69,29 @@ def __init__( self.text = text +class PlanUpdateChunk(Chunk): + type = "plan_update" + + @property + def attributes(self) -> Set[str]: # type: ignore[override] + return super().attributes.union({"title"}) + + def __init__( + self, + *, + title: str, + **others: Dict, + ): + """An updated title of plans for task and tool calls. + + https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming + """ + super().__init__(type=self.type) + show_unknown_key_warning(self, others) + + self.title = title + + class URLSource(JsonObject): type = "url" diff --git a/tests/slack_sdk/models/test_chunks.py b/tests/slack_sdk/models/test_chunks.py index 1b8b58c9..6d64bd17 100644 --- a/tests/slack_sdk/models/test_chunks.py +++ b/tests/slack_sdk/models/test_chunks.py @@ -1,6 +1,6 @@ import unittest -from slack_sdk.models.messages.chunk import MarkdownTextChunk, TaskUpdateChunk, URLSource +from slack_sdk.models.messages.chunk import MarkdownTextChunk, PlanUpdateChunk, TaskUpdateChunk, URLSource class MarkdownTextChunkTests(unittest.TestCase): @@ -14,6 +14,17 @@ def test_json(self): ) +class PlanUpdateChunkTests(unittest.TestCase): + def test_json(self): + self.assertDictEqual( + PlanUpdateChunk(title="Crunching numbers...").to_dict(), + { + "type": "plan_update", + "title": "Crunching numbers...", + }, + ) + + class TaskUpdateChunkTests(unittest.TestCase): def test_json(self): self.assertDictEqual( diff --git a/tests/slack_sdk/web/test_internal_utils.py b/tests/slack_sdk/web/test_internal_utils.py index fc6574aa..3e44f0c9 100644 --- a/tests/slack_sdk/web/test_internal_utils.py +++ b/tests/slack_sdk/web/test_internal_utils.py @@ -4,10 +4,9 @@ from pathlib import Path from typing import Dict - from slack_sdk.models.attachments import Attachment from slack_sdk.models.blocks import Block, DividerBlock -from slack_sdk.models.messages.chunk import MarkdownTextChunk, TaskUpdateChunk +from slack_sdk.models.messages.chunk import MarkdownTextChunk, PlanUpdateChunk, TaskUpdateChunk from slack_sdk.web.internal_utils import ( _build_unexpected_body_error_message, _get_url, @@ -59,9 +58,14 @@ def test_can_parse_sequence_of_attachments(self): def test_can_parse_sequence_of_chunks(self): for chunks in [ - [MarkdownTextChunk(text="fiz"), TaskUpdateChunk(id="001", title="baz", status="complete")], # list + [ + MarkdownTextChunk(text="fiz"), + PlanUpdateChunk(title="fuz"), + TaskUpdateChunk(id="001", title="baz", status="complete"), + ], # list ( MarkdownTextChunk(text="fiz"), + PlanUpdateChunk(title="fuz"), TaskUpdateChunk(id="001", title="baz", status="complete"), ), # tuple ]: @@ -87,7 +91,11 @@ def test_can_parse_str_attachments(self): def test_can_parse_str_chunks(self): input = json.dumps( - [MarkdownTextChunk(text="fiz").to_dict(), TaskUpdateChunk(id="001", title="baz", status="complete").to_dict()] + [ + MarkdownTextChunk(text="fiz").to_dict(), + PlanUpdateChunk(title="fuz").to_dict(), + TaskUpdateChunk(id="001", title="baz", status="complete").to_dict(), + ] ) kwargs = {"chunks": input} _parse_web_class_objects(kwargs)