Skip to content
Open
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
25 changes: 25 additions & 0 deletions slack_sdk/models/messages/chunk.py
Copy link
Contributor

Choose a reason for hiding this comment

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

🌟

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for getting clarification on what this chunk should look like 😸



class URLSource(JsonObject):
type = "url"

Expand Down
13 changes: 12 additions & 1 deletion tests/slack_sdk/models/test_chunks.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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(
Expand Down
16 changes: 12 additions & 4 deletions tests/slack_sdk/web/test_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
]:
Expand All @@ -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)
Expand Down
Loading