From 73e46fd0bba673533303eeb7858a4e1f0a016198 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 30 Sep 2025 21:32:58 -0700 Subject: [PATCH 01/18] feat(web-api): add a chat stream method to the web client --- docs/reference/index.html | 163 +++++++ docs/reference/web/async_chat_stream.html | 406 ++++++++++++++++++ docs/reference/web/async_client.html | 163 +++++++ docs/reference/web/chat_stream.html | 398 +++++++++++++++++ docs/reference/web/client.html | 163 +++++++ docs/reference/web/index.html | 173 ++++++++ docs/reference/web/legacy_client.html | 163 +++++++ slack_sdk/web/async_chat_stream.py | 166 +++++++ slack_sdk/web/async_client.py | 59 +++ slack_sdk/web/chat_stream.py | 162 +++++++ slack_sdk/web/client.py | 59 +++ slack_sdk/web/legacy_client.py | 59 +++ tests/slack_sdk/web/test_chat_stream.py | 142 ++++++ .../web_response_chat_stream_test.json | 4 + 14 files changed, 2280 insertions(+) create mode 100644 docs/reference/web/async_chat_stream.html create mode 100644 docs/reference/web/chat_stream.html create mode 100644 slack_sdk/web/async_chat_stream.py create mode 100644 slack_sdk/web/chat_stream.py create mode 100644 tests/slack_sdk/web/test_chat_stream.py create mode 100644 tests/slack_sdk_fixture/web_response_chat_stream_test.json diff --git a/docs/reference/index.html b/docs/reference/index.html index 0245eb5ff..6cd8cbbeb 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -3030,6 +3030,64 @@

Classes

kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, @@ -10346,6 +10404,110 @@

Methods

Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

+
+def chat_stream(self,
*,
buffer_size: int | None = 256,
channel: str,
thread_ts: str,
recipient_team_id: str | None = None,
recipient_user_id: str | None = None,
unfurl_links: bool | None = None,
unfurl_media: bool | None = None,
**kwargs) ‑> ChatStream
+
+
+
+ +Expand source code + +
def chat_stream(
+    self,
+    *,
+    buffer_size: Optional[int] = 256,
+    channel: str,
+    thread_ts: str,
+    recipient_team_id: Optional[str] = None,
+    recipient_user_id: Optional[str] = None,
+    unfurl_links: Optional[bool] = None,
+    unfurl_media: Optional[bool] = None,
+    **kwargs,
+) -> ChatStream:
+    """Stream markdown text into a conversation.
+
+    This method provides an easy way to stream markdown text using the following endpoints:
+    - chat.startStream: Starts a new streaming conversation
+    - chat.appendStream: Appends text to an existing streaming conversation
+    - chat.stopStream: Stops a streaming conversation
+
+    Args:
+        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
+        channel: Channel to stream to
+        thread_ts: Thread timestamp to stream to (required)
+        recipient_team_id: Team ID of the recipient (for Slack Connect)
+        recipient_user_id: User ID of the recipient (for Slack Connect)
+        unfurl_links: Whether to unfurl links
+        unfurl_media: Whether to unfurl media
+        **kwargs: Additional arguments passed to the underlying API calls
+
+    Returns:
+        ChatStreamer instance for managing the stream
+
+    Example:
+        ```python
+        streamer = client.chat_stream(
+            channel="C0123456789",
+            thread_ts="1700000001.123456",
+            recipient_team_id="T0123456789",
+            recipient_user_id="U0123456789",
+        )
+        streamer.append(markdown_text="**hello wo")
+        streamer.append(markdown_text="rld!**")
+        streamer.stop()
+        ```
+    """
+    return ChatStream(
+        self,
+        logger=self._logger,
+        channel=channel,
+        thread_ts=thread_ts,
+        recipient_team_id=recipient_team_id,
+        recipient_user_id=recipient_user_id,
+        unfurl_links=unfurl_links,
+        unfurl_media=unfurl_media,
+        buffer_size=buffer_size,
+        **kwargs,
+    )
+
+

Stream markdown text into a conversation.

+

This method provides an easy way to stream markdown text using the following endpoints: +- chat.startStream: Starts a new streaming conversation +- chat.appendStream: Appends text to an existing streaming conversation +- chat.stopStream: Stops a streaming conversation

+

Args

+
+
buffer_size
+
Size of the internal buffer before automatically flushing (default: 256)
+
channel
+
Channel to stream to
+
thread_ts
+
Thread timestamp to stream to (required)
+
recipient_team_id
+
Team ID of the recipient (for Slack Connect)
+
recipient_user_id
+
User ID of the recipient (for Slack Connect)
+
unfurl_links
+
Whether to unfurl links
+
unfurl_media
+
Whether to unfurl media
+
**kwargs
+
Additional arguments passed to the underlying API calls
+
+

Returns

+

ChatStreamer instance for managing the stream

+

Example

+
streamer = client.chat_stream(
+    channel="C0123456789",
+    thread_ts="1700000001.123456",
+    recipient_team_id="T0123456789",
+    recipient_user_id="U0123456789",
+)
+streamer.append(markdown_text="**hello wo")
+streamer.append(markdown_text="rld!**")
+streamer.stop()
+
+
def chat_unfurl(self,
*,
channel: str | None = None,
ts: str | None = None,
source: str | None = None,
unfurl_id: str | None = None,
unfurls: Dict[str, Dict] | None = None,
user_auth_blocks: str | Sequence[Dict | Block] | None = None,
user_auth_message: str | None = None,
user_auth_required: bool | None = None,
user_auth_url: str | None = None,
**kwargs) ‑> SlackResponse
@@ -15323,6 +15485,7 @@

WebClientchat_scheduledMessages_list
  • chat_startStream
  • chat_stopStream
  • +
  • chat_stream
  • chat_unfurl
  • chat_update
  • conversations_acceptSharedInvite
  • diff --git a/docs/reference/web/async_chat_stream.html b/docs/reference/web/async_chat_stream.html new file mode 100644 index 000000000..8c7900814 --- /dev/null +++ b/docs/reference/web/async_chat_stream.html @@ -0,0 +1,406 @@ + + + + + + +slack_sdk.web.async_chat_stream API documentation + + + + + + + + + + + +
    +
    +
    +

    Module slack_sdk.web.async_chat_stream

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class AsyncChatStream +(client: AsyncWebClient,
    *,
    channel: str,
    logger: logging.Logger,
    thread_ts: str,
    buffer_size: int,
    recipient_team_id: str | None = None,
    recipient_user_id: str | None = None,
    unfurl_links: bool | None = None,
    unfurl_media: bool | None = None,
    **kwargs)
    +
    +
    +
    + +Expand source code + +
    class AsyncChatStream:
    +    """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
    +
    +    This class provides a convenient interface for the chat.startStream, chat.appendStream,
    +    and chat.stopStream API methods, with automatic buffering and state management.
    +    """
    +
    +    def __init__(
    +        self,
    +        client: "AsyncWebClient",
    +        *,
    +        channel: str,
    +        logger: logging.Logger,
    +        thread_ts: str,
    +        buffer_size: int,
    +        recipient_team_id: Optional[str] = None,
    +        recipient_user_id: Optional[str] = None,
    +        unfurl_links: Optional[bool] = None,
    +        unfurl_media: Optional[bool] = None,
    +        **kwargs,
    +    ):
    +        """Initialize a new ChatStream instance.
    +
    +        Args:
    +            client: The WebClient instance to use for API calls
    +            channel: Channel ID to stream to
    +            thread_ts: Thread timestamp to stream to
    +            recipient_team_id: Team ID of the recipient
    +            recipient_user_id: User ID of the recipient
    +            unfurl_links: Whether to unfurl links
    +            unfurl_media: Whether to unfurl media
    +            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
    +        """
    +        self._client = client
    +        self._logger = logger
    +        self._stream_args = {
    +            "channel": channel,
    +            "thread_ts": thread_ts,
    +            "recipient_team_id": recipient_team_id,
    +            "recipient_user_id": recipient_user_id,
    +            "unfurl_links": unfurl_links,
    +            "unfurl_media": unfurl_media,
    +            **kwargs,
    +        }
    +        self._buffer = ""
    +        self._state = "starting"
    +        self._stream_ts: Optional[str] = None
    +        self._buffer_size = buffer_size
    +
    +    async def append(
    +        self,
    +        *,
    +        markdown_text: str,
    +        **kwargs,
    +    ) -> Optional[AsyncSlackResponse]:
    +        """Append markdown text to the stream.
    +
    +        Args:
    +            markdown_text: The markdown text to append
    +            **kwargs: Additional arguments passed to the underlying API calls
    +
    +        Returns:
    +            AsyncSlackResponse if the buffer was flushed, None if buffering
    +
    +        Raises:
    +            SlackRequestError: If the stream is already completed
    +        """
    +        if self._state == "completed":
    +            raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
    +        self._buffer += markdown_text
    +        if len(self._buffer) >= self._buffer_size:
    +            return await self._flush_buffer(**kwargs)
    +        details = {
    +            "buffer_length": len(self._buffer),
    +            "buffer_size": self._buffer_size,
    +            "channel": self._stream_args.get("channel"),
    +            "recipient_team_id": self._stream_args.get("recipient_team_id"),
    +            "recipient_user_id": self._stream_args.get("recipient_user_id"),
    +            "thread_ts": self._stream_args.get("thread_ts"),
    +        }
    +        self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}")
    +        return None
    +
    +    async def stop(
    +        self,
    +        *,
    +        markdown_text: Optional[str] = None,
    +        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
    +        metadata: Optional[Union[Dict, Metadata]] = None,
    +        **kwargs,
    +    ) -> AsyncSlackResponse:
    +        """Stop the stream and finalize the message.
    +
    +        Args:
    +            markdown_text: Additional markdown text to append before stopping
    +            blocks: Message blocks to add to the final message
    +            metadata: Message metadata to add to the final message
    +            **kwargs: Additional arguments passed to the underlying API calls
    +
    +        Returns:
    +            AsyncSlackResponse from the chat.stopStream API call
    +
    +        Raises:
    +            SlackRequestError: If the stream is already completed
    +        """
    +        if self._state == "completed":
    +            raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
    +        if markdown_text:
    +            self._buffer += markdown_text
    +        if not self._stream_ts:
    +            response = await self._client.chat_startStream(
    +                **self._stream_args,
    +                **kwargs,
    +            )
    +            if not response.get("ts"):
    +                raise e.SlackRequestError("Failed to stop stream: stream not started")
    +            self._stream_ts = str(response["ts"])
    +            self._state = "in_progress"
    +
    +        print(f"_stream_args: {self._stream_args}\n")  # todo
    +        print(f"_buffer: {self._buffer}\n")
    +
    +        response = await self._client.chat_stopStream(
    +            channel=self._stream_args["channel"],
    +            ts=self._stream_ts,
    +            blocks=blocks,
    +            markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""),
    +            metadata=metadata,
    +            **kwargs,
    +        )
    +        self._state = "completed"
    +        return response
    +
    +    async def _flush_buffer(self, **kwargs) -> AsyncSlackResponse:
    +        """Flush the internal buffer by making appropriate API calls."""
    +        if not self._stream_ts:
    +            response = await self._client.chat_startStream(
    +                **self._stream_args,
    +                markdown_text=self._buffer,
    +                **kwargs,
    +            )
    +            self._stream_ts = response.get("ts")
    +            self._state = "in_progress"
    +        else:
    +            response = await self._client.chat_appendStream(
    +                channel=self._stream_args["channel"],
    +                ts=self._stream_ts,
    +                markdown_text=self._buffer,
    +                **kwargs,
    +            )
    +
    +        self._buffer = ""
    +        return response
    +
    +

    A helper class for streaming markdown text into a conversation using the chat streaming APIs.

    +

    This class provides a convenient interface for the chat.startStream, chat.appendStream, +and chat.stopStream API methods, with automatic buffering and state management.

    +

    Initialize a new ChatStream instance.

    +

    Args

    +
    +
    client
    +
    The WebClient instance to use for API calls
    +
    channel
    +
    Channel ID to stream to
    +
    thread_ts
    +
    Thread timestamp to stream to
    +
    recipient_team_id
    +
    Team ID of the recipient
    +
    recipient_user_id
    +
    User ID of the recipient
    +
    unfurl_links
    +
    Whether to unfurl links
    +
    unfurl_media
    +
    Whether to unfurl media
    +
    buffer_size
    +
    Size of the internal buffer before automatically flushing (default: 256)
    +
    +

    Methods

    +
    +
    +async def append(self, *, markdown_text: str, **kwargs) ‑> AsyncSlackResponse | None +
    +
    +
    + +Expand source code + +
    async def append(
    +    self,
    +    *,
    +    markdown_text: str,
    +    **kwargs,
    +) -> Optional[AsyncSlackResponse]:
    +    """Append markdown text to the stream.
    +
    +    Args:
    +        markdown_text: The markdown text to append
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        AsyncSlackResponse if the buffer was flushed, None if buffering
    +
    +    Raises:
    +        SlackRequestError: If the stream is already completed
    +    """
    +    if self._state == "completed":
    +        raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
    +    self._buffer += markdown_text
    +    if len(self._buffer) >= self._buffer_size:
    +        return await self._flush_buffer(**kwargs)
    +    details = {
    +        "buffer_length": len(self._buffer),
    +        "buffer_size": self._buffer_size,
    +        "channel": self._stream_args.get("channel"),
    +        "recipient_team_id": self._stream_args.get("recipient_team_id"),
    +        "recipient_user_id": self._stream_args.get("recipient_user_id"),
    +        "thread_ts": self._stream_args.get("thread_ts"),
    +    }
    +    self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}")
    +    return None
    +
    +

    Append markdown text to the stream.

    +

    Args

    +
    +
    markdown_text
    +
    The markdown text to append
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    AsyncSlackResponse if the buffer was flushed, None if buffering

    +

    Raises

    +
    +
    SlackRequestError
    +
    If the stream is already completed
    +
    +
    +
    +async def stop(self,
    *,
    markdown_text: str | None = None,
    blocks: str | Sequence[Dict | Block] | None = None,
    metadata: Dict | Metadata | None = None,
    **kwargs) ‑> AsyncSlackResponse
    +
    +
    +
    + +Expand source code + +
    async def stop(
    +    self,
    +    *,
    +    markdown_text: Optional[str] = None,
    +    blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
    +    metadata: Optional[Union[Dict, Metadata]] = None,
    +    **kwargs,
    +) -> AsyncSlackResponse:
    +    """Stop the stream and finalize the message.
    +
    +    Args:
    +        markdown_text: Additional markdown text to append before stopping
    +        blocks: Message blocks to add to the final message
    +        metadata: Message metadata to add to the final message
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        AsyncSlackResponse from the chat.stopStream API call
    +
    +    Raises:
    +        SlackRequestError: If the stream is already completed
    +    """
    +    if self._state == "completed":
    +        raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
    +    if markdown_text:
    +        self._buffer += markdown_text
    +    if not self._stream_ts:
    +        response = await self._client.chat_startStream(
    +            **self._stream_args,
    +            **kwargs,
    +        )
    +        if not response.get("ts"):
    +            raise e.SlackRequestError("Failed to stop stream: stream not started")
    +        self._stream_ts = str(response["ts"])
    +        self._state = "in_progress"
    +
    +    print(f"_stream_args: {self._stream_args}\n")  # todo
    +    print(f"_buffer: {self._buffer}\n")
    +
    +    response = await self._client.chat_stopStream(
    +        channel=self._stream_args["channel"],
    +        ts=self._stream_ts,
    +        blocks=blocks,
    +        markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""),
    +        metadata=metadata,
    +        **kwargs,
    +    )
    +    self._state = "completed"
    +    return response
    +
    +

    Stop the stream and finalize the message.

    +

    Args

    +
    +
    markdown_text
    +
    Additional markdown text to append before stopping
    +
    blocks
    +
    Message blocks to add to the final message
    +
    metadata
    +
    Message metadata to add to the final message
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    AsyncSlackResponse from the chat.stopStream API call

    +

    Raises

    +
    +
    SlackRequestError
    +
    If the stream is already completed
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + diff --git a/docs/reference/web/async_client.html b/docs/reference/web/async_client.html index 9d895fea8..3ee659eb4 100644 --- a/docs/reference/web/async_client.html +++ b/docs/reference/web/async_client.html @@ -2926,6 +2926,64 @@

    Classes

    kwargs = _remove_none_values(kwargs) return await self.api_call("chat.startStream", json=kwargs) + async def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + async def chat_stopStream( self, *, @@ -10242,6 +10300,110 @@

    Methods

    Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

    +
    +async def chat_stream(self,
    *,
    buffer_size: int | None = 256,
    channel: str,
    thread_ts: str,
    recipient_team_id: str | None = None,
    recipient_user_id: str | None = None,
    unfurl_links: bool | None = None,
    unfurl_media: bool | None = None,
    **kwargs) ‑> ChatStream
    +
    +
    +
    + +Expand source code + +
    async def chat_stream(
    +    self,
    +    *,
    +    buffer_size: Optional[int] = 256,
    +    channel: str,
    +    thread_ts: str,
    +    recipient_team_id: Optional[str] = None,
    +    recipient_user_id: Optional[str] = None,
    +    unfurl_links: Optional[bool] = None,
    +    unfurl_media: Optional[bool] = None,
    +    **kwargs,
    +) -> ChatStream:
    +    """Stream markdown text into a conversation.
    +
    +    This method provides an easy way to stream markdown text using the following endpoints:
    +    - chat.startStream: Starts a new streaming conversation
    +    - chat.appendStream: Appends text to an existing streaming conversation
    +    - chat.stopStream: Stops a streaming conversation
    +
    +    Args:
    +        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
    +        channel: Channel to stream to
    +        thread_ts: Thread timestamp to stream to (required)
    +        recipient_team_id: Team ID of the recipient (for Slack Connect)
    +        recipient_user_id: User ID of the recipient (for Slack Connect)
    +        unfurl_links: Whether to unfurl links
    +        unfurl_media: Whether to unfurl media
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        ChatStreamer instance for managing the stream
    +
    +    Example:
    +        ```python
    +        streamer = client.chat_stream(
    +            channel="C0123456789",
    +            thread_ts="1700000001.123456",
    +            recipient_team_id="T0123456789",
    +            recipient_user_id="U0123456789",
    +        )
    +        streamer.append(markdown_text="**hello wo")
    +        streamer.append(markdown_text="rld!**")
    +        streamer.stop()
    +        ```
    +    """
    +    return ChatStream(
    +        self,
    +        logger=self._logger,
    +        channel=channel,
    +        thread_ts=thread_ts,
    +        recipient_team_id=recipient_team_id,
    +        recipient_user_id=recipient_user_id,
    +        unfurl_links=unfurl_links,
    +        unfurl_media=unfurl_media,
    +        buffer_size=buffer_size,
    +        **kwargs,
    +    )
    +
    +

    Stream markdown text into a conversation.

    +

    This method provides an easy way to stream markdown text using the following endpoints: +- chat.startStream: Starts a new streaming conversation +- chat.appendStream: Appends text to an existing streaming conversation +- chat.stopStream: Stops a streaming conversation

    +

    Args

    +
    +
    buffer_size
    +
    Size of the internal buffer before automatically flushing (default: 256)
    +
    channel
    +
    Channel to stream to
    +
    thread_ts
    +
    Thread timestamp to stream to (required)
    +
    recipient_team_id
    +
    Team ID of the recipient (for Slack Connect)
    +
    recipient_user_id
    +
    User ID of the recipient (for Slack Connect)
    +
    unfurl_links
    +
    Whether to unfurl links
    +
    unfurl_media
    +
    Whether to unfurl media
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    ChatStreamer instance for managing the stream

    +

    Example

    +
    streamer = client.chat_stream(
    +    channel="C0123456789",
    +    thread_ts="1700000001.123456",
    +    recipient_team_id="T0123456789",
    +    recipient_user_id="U0123456789",
    +)
    +streamer.append(markdown_text="**hello wo")
    +streamer.append(markdown_text="rld!**")
    +streamer.stop()
    +
    +
    async def chat_unfurl(self,
    *,
    channel: str | None = None,
    ts: str | None = None,
    source: str | None = None,
    unfurl_id: str | None = None,
    unfurls: Dict[str, Dict] | None = None,
    user_auth_blocks: str | Sequence[Dict | Block] | None = None,
    user_auth_message: str | None = None,
    user_auth_required: bool | None = None,
    user_auth_url: str | None = None,
    **kwargs) ‑> AsyncSlackResponse
    @@ -14759,6 +14921,7 @@

    chat_scheduledMessages_list
  • chat_startStream
  • chat_stopStream
  • +
  • chat_stream
  • chat_unfurl
  • chat_update
  • conversations_acceptSharedInvite
  • diff --git a/docs/reference/web/chat_stream.html b/docs/reference/web/chat_stream.html new file mode 100644 index 000000000..c23ae4343 --- /dev/null +++ b/docs/reference/web/chat_stream.html @@ -0,0 +1,398 @@ + + + + + + +slack_sdk.web.chat_stream API documentation + + + + + + + + + + + +
    +
    +
    +

    Module slack_sdk.web.chat_stream

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class ChatStream +(client: WebClient,
    *,
    channel: str,
    logger: logging.Logger,
    thread_ts: str,
    buffer_size: int,
    recipient_team_id: str | None = None,
    recipient_user_id: str | None = None,
    unfurl_links: bool | None = None,
    unfurl_media: bool | None = None,
    **kwargs)
    +
    +
    +
    + +Expand source code + +
    class ChatStream:
    +    """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
    +
    +    This class provides a convenient interface for the chat.startStream, chat.appendStream,
    +    and chat.stopStream API methods, with automatic buffering and state management.
    +    """
    +
    +    def __init__(
    +        self,
    +        client: "WebClient",
    +        *,
    +        channel: str,
    +        logger: logging.Logger,
    +        thread_ts: str,
    +        buffer_size: int,
    +        recipient_team_id: Optional[str] = None,
    +        recipient_user_id: Optional[str] = None,
    +        unfurl_links: Optional[bool] = None,
    +        unfurl_media: Optional[bool] = None,
    +        **kwargs,
    +    ):
    +        """Initialize a new ChatStream instance.
    +
    +        Args:
    +            client: The WebClient instance to use for API calls
    +            channel: Channel ID to stream to
    +            thread_ts: Thread timestamp to stream to
    +            recipient_team_id: Team ID of the recipient
    +            recipient_user_id: User ID of the recipient
    +            unfurl_links: Whether to unfurl links
    +            unfurl_media: Whether to unfurl media
    +            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
    +        """
    +        self._client = client
    +        self._logger = logger
    +        self._stream_args = {
    +            "channel": channel,
    +            "thread_ts": thread_ts,
    +            "recipient_team_id": recipient_team_id,
    +            "recipient_user_id": recipient_user_id,
    +            "unfurl_links": unfurl_links,
    +            "unfurl_media": unfurl_media,
    +            **kwargs,
    +        }
    +        self._buffer = ""
    +        self._state = "starting"
    +        self._stream_ts: Optional[str] = None
    +        self._buffer_size = buffer_size
    +
    +    def append(
    +        self,
    +        *,
    +        markdown_text: str,
    +        **kwargs,
    +    ) -> Optional[SlackResponse]:
    +        """Append markdown text to the stream.
    +
    +        Args:
    +            markdown_text: The markdown text to append
    +            **kwargs: Additional arguments passed to the underlying API calls
    +
    +        Returns:
    +            SlackResponse if the buffer was flushed, None if buffering
    +
    +        Raises:
    +            SlackRequestError: If the stream is already completed
    +        """
    +        if self._state == "completed":
    +            raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
    +        self._buffer += markdown_text
    +        if len(self._buffer) >= self._buffer_size:
    +            return self._flush_buffer(**kwargs)
    +        details = {
    +            "buffer_length": len(self._buffer),
    +            "buffer_size": self._buffer_size,
    +            "channel": self._stream_args.get("channel"),
    +            "recipient_team_id": self._stream_args.get("recipient_team_id"),
    +            "recipient_user_id": self._stream_args.get("recipient_user_id"),
    +            "thread_ts": self._stream_args.get("thread_ts"),
    +        }
    +        self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}")
    +        return None
    +
    +    def stop(
    +        self,
    +        *,
    +        markdown_text: Optional[str] = None,
    +        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
    +        metadata: Optional[Union[Dict, Metadata]] = None,
    +        **kwargs,
    +    ) -> SlackResponse:
    +        """Stop the stream and finalize the message.
    +
    +        Args:
    +            markdown_text: Additional markdown text to append before stopping
    +            blocks: Message blocks to add to the final message
    +            metadata: Message metadata to add to the final message
    +            **kwargs: Additional arguments passed to the underlying API calls
    +
    +        Returns:
    +            SlackResponse from the chat.stopStream API call
    +
    +        Raises:
    +            SlackRequestError: If the stream is already completed
    +        """
    +        if self._state == "completed":
    +            raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
    +        if markdown_text:
    +            self._buffer += markdown_text
    +        if not self._stream_ts:
    +            response = self._client.chat_startStream(
    +                **self._stream_args,
    +                **kwargs,
    +            )
    +            if not response.get("ts"):
    +                raise e.SlackRequestError("Failed to stop stream: stream not started")
    +            self._stream_ts = str(response["ts"])
    +            self._state = "in_progress"
    +        response = self._client.chat_stopStream(
    +            channel=self._stream_args["channel"],
    +            ts=self._stream_ts,
    +            blocks=blocks,
    +            markdown_text=self._buffer,
    +            metadata=metadata,
    +            **kwargs,
    +        )
    +        self._state = "completed"
    +        return response
    +
    +    def _flush_buffer(self, **kwargs) -> SlackResponse:
    +        """Flush the internal buffer by making appropriate API calls."""
    +        if not self._stream_ts:
    +            response = self._client.chat_startStream(
    +                **self._stream_args,
    +                markdown_text=self._buffer,
    +                **kwargs,
    +            )
    +            self._stream_ts = response.get("ts")
    +            self._state = "in_progress"
    +        else:
    +            response = self._client.chat_appendStream(
    +                channel=self._stream_args["channel"],
    +                ts=self._stream_ts,
    +                markdown_text=self._buffer,
    +                **kwargs,
    +            )
    +
    +        self._buffer = ""
    +        return response
    +
    +

    A helper class for streaming markdown text into a conversation using the chat streaming APIs.

    +

    This class provides a convenient interface for the chat.startStream, chat.appendStream, +and chat.stopStream API methods, with automatic buffering and state management.

    +

    Initialize a new ChatStream instance.

    +

    Args

    +
    +
    client
    +
    The WebClient instance to use for API calls
    +
    channel
    +
    Channel ID to stream to
    +
    thread_ts
    +
    Thread timestamp to stream to
    +
    recipient_team_id
    +
    Team ID of the recipient
    +
    recipient_user_id
    +
    User ID of the recipient
    +
    unfurl_links
    +
    Whether to unfurl links
    +
    unfurl_media
    +
    Whether to unfurl media
    +
    buffer_size
    +
    Size of the internal buffer before automatically flushing (default: 256)
    +
    +

    Methods

    +
    +
    +def append(self, *, markdown_text: str, **kwargs) ‑> SlackResponse | None +
    +
    +
    + +Expand source code + +
    def append(
    +    self,
    +    *,
    +    markdown_text: str,
    +    **kwargs,
    +) -> Optional[SlackResponse]:
    +    """Append markdown text to the stream.
    +
    +    Args:
    +        markdown_text: The markdown text to append
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        SlackResponse if the buffer was flushed, None if buffering
    +
    +    Raises:
    +        SlackRequestError: If the stream is already completed
    +    """
    +    if self._state == "completed":
    +        raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
    +    self._buffer += markdown_text
    +    if len(self._buffer) >= self._buffer_size:
    +        return self._flush_buffer(**kwargs)
    +    details = {
    +        "buffer_length": len(self._buffer),
    +        "buffer_size": self._buffer_size,
    +        "channel": self._stream_args.get("channel"),
    +        "recipient_team_id": self._stream_args.get("recipient_team_id"),
    +        "recipient_user_id": self._stream_args.get("recipient_user_id"),
    +        "thread_ts": self._stream_args.get("thread_ts"),
    +    }
    +    self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}")
    +    return None
    +
    +

    Append markdown text to the stream.

    +

    Args

    +
    +
    markdown_text
    +
    The markdown text to append
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    SlackResponse if the buffer was flushed, None if buffering

    +

    Raises

    +
    +
    SlackRequestError
    +
    If the stream is already completed
    +
    +
    +
    +def stop(self,
    *,
    markdown_text: str | None = None,
    blocks: str | Sequence[Dict | Block] | None = None,
    metadata: Dict | Metadata | None = None,
    **kwargs) ‑> SlackResponse
    +
    +
    +
    + +Expand source code + +
    def stop(
    +    self,
    +    *,
    +    markdown_text: Optional[str] = None,
    +    blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
    +    metadata: Optional[Union[Dict, Metadata]] = None,
    +    **kwargs,
    +) -> SlackResponse:
    +    """Stop the stream and finalize the message.
    +
    +    Args:
    +        markdown_text: Additional markdown text to append before stopping
    +        blocks: Message blocks to add to the final message
    +        metadata: Message metadata to add to the final message
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        SlackResponse from the chat.stopStream API call
    +
    +    Raises:
    +        SlackRequestError: If the stream is already completed
    +    """
    +    if self._state == "completed":
    +        raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
    +    if markdown_text:
    +        self._buffer += markdown_text
    +    if not self._stream_ts:
    +        response = self._client.chat_startStream(
    +            **self._stream_args,
    +            **kwargs,
    +        )
    +        if not response.get("ts"):
    +            raise e.SlackRequestError("Failed to stop stream: stream not started")
    +        self._stream_ts = str(response["ts"])
    +        self._state = "in_progress"
    +    response = self._client.chat_stopStream(
    +        channel=self._stream_args["channel"],
    +        ts=self._stream_ts,
    +        blocks=blocks,
    +        markdown_text=self._buffer,
    +        metadata=metadata,
    +        **kwargs,
    +    )
    +    self._state = "completed"
    +    return response
    +
    +

    Stop the stream and finalize the message.

    +

    Args

    +
    +
    markdown_text
    +
    Additional markdown text to append before stopping
    +
    blocks
    +
    Message blocks to add to the final message
    +
    metadata
    +
    Message metadata to add to the final message
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    SlackResponse from the chat.stopStream API call

    +

    Raises

    +
    +
    SlackRequestError
    +
    If the stream is already completed
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + diff --git a/docs/reference/web/client.html b/docs/reference/web/client.html index e6704424c..0ad9ca23b 100644 --- a/docs/reference/web/client.html +++ b/docs/reference/web/client.html @@ -2926,6 +2926,64 @@

    Classes

    kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, @@ -10242,6 +10300,110 @@

    Methods

    Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

    +
    +def chat_stream(self,
    *,
    buffer_size: int | None = 256,
    channel: str,
    thread_ts: str,
    recipient_team_id: str | None = None,
    recipient_user_id: str | None = None,
    unfurl_links: bool | None = None,
    unfurl_media: bool | None = None,
    **kwargs) ‑> ChatStream
    +
    +
    +
    + +Expand source code + +
    def chat_stream(
    +    self,
    +    *,
    +    buffer_size: Optional[int] = 256,
    +    channel: str,
    +    thread_ts: str,
    +    recipient_team_id: Optional[str] = None,
    +    recipient_user_id: Optional[str] = None,
    +    unfurl_links: Optional[bool] = None,
    +    unfurl_media: Optional[bool] = None,
    +    **kwargs,
    +) -> ChatStream:
    +    """Stream markdown text into a conversation.
    +
    +    This method provides an easy way to stream markdown text using the following endpoints:
    +    - chat.startStream: Starts a new streaming conversation
    +    - chat.appendStream: Appends text to an existing streaming conversation
    +    - chat.stopStream: Stops a streaming conversation
    +
    +    Args:
    +        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
    +        channel: Channel to stream to
    +        thread_ts: Thread timestamp to stream to (required)
    +        recipient_team_id: Team ID of the recipient (for Slack Connect)
    +        recipient_user_id: User ID of the recipient (for Slack Connect)
    +        unfurl_links: Whether to unfurl links
    +        unfurl_media: Whether to unfurl media
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        ChatStreamer instance for managing the stream
    +
    +    Example:
    +        ```python
    +        streamer = client.chat_stream(
    +            channel="C0123456789",
    +            thread_ts="1700000001.123456",
    +            recipient_team_id="T0123456789",
    +            recipient_user_id="U0123456789",
    +        )
    +        streamer.append(markdown_text="**hello wo")
    +        streamer.append(markdown_text="rld!**")
    +        streamer.stop()
    +        ```
    +    """
    +    return ChatStream(
    +        self,
    +        logger=self._logger,
    +        channel=channel,
    +        thread_ts=thread_ts,
    +        recipient_team_id=recipient_team_id,
    +        recipient_user_id=recipient_user_id,
    +        unfurl_links=unfurl_links,
    +        unfurl_media=unfurl_media,
    +        buffer_size=buffer_size,
    +        **kwargs,
    +    )
    +
    +

    Stream markdown text into a conversation.

    +

    This method provides an easy way to stream markdown text using the following endpoints: +- chat.startStream: Starts a new streaming conversation +- chat.appendStream: Appends text to an existing streaming conversation +- chat.stopStream: Stops a streaming conversation

    +

    Args

    +
    +
    buffer_size
    +
    Size of the internal buffer before automatically flushing (default: 256)
    +
    channel
    +
    Channel to stream to
    +
    thread_ts
    +
    Thread timestamp to stream to (required)
    +
    recipient_team_id
    +
    Team ID of the recipient (for Slack Connect)
    +
    recipient_user_id
    +
    User ID of the recipient (for Slack Connect)
    +
    unfurl_links
    +
    Whether to unfurl links
    +
    unfurl_media
    +
    Whether to unfurl media
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    ChatStreamer instance for managing the stream

    +

    Example

    +
    streamer = client.chat_stream(
    +    channel="C0123456789",
    +    thread_ts="1700000001.123456",
    +    recipient_team_id="T0123456789",
    +    recipient_user_id="U0123456789",
    +)
    +streamer.append(markdown_text="**hello wo")
    +streamer.append(markdown_text="rld!**")
    +streamer.stop()
    +
    +
    def chat_unfurl(self,
    *,
    channel: str | None = None,
    ts: str | None = None,
    source: str | None = None,
    unfurl_id: str | None = None,
    unfurls: Dict[str, Dict] | None = None,
    user_auth_blocks: str | Sequence[Dict | Block] | None = None,
    user_auth_message: str | None = None,
    user_auth_required: bool | None = None,
    user_auth_url: str | None = None,
    **kwargs) ‑> SlackResponse
    @@ -14758,6 +14920,7 @@

    chat_scheduledMessages_list
  • chat_startStream
  • chat_stopStream
  • +
  • chat_stream
  • chat_unfurl
  • chat_update
  • conversations_acceptSharedInvite
  • diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html index 2e9c01af9..38087d56f 100644 --- a/docs/reference/web/index.html +++ b/docs/reference/web/index.html @@ -47,6 +47,10 @@

    Sub-modules

    +
    slack_sdk.web.async_chat_stream
    +
    +
    +
    slack_sdk.web.async_client

    A Python module for interacting with Slack's Web API.

    @@ -63,6 +67,10 @@

    Sub-modules

    A Python module for interacting with Slack's Web API.

    +
    slack_sdk.web.chat_stream
    +
    +
    +
    slack_sdk.web.client

    A Python module for interacting with Slack's Web API.

    @@ -3287,6 +3295,64 @@

    Raises

    kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, @@ -10603,6 +10669,110 @@

    Methods

    Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

    +
    +def chat_stream(self,
    *,
    buffer_size: int | None = 256,
    channel: str,
    thread_ts: str,
    recipient_team_id: str | None = None,
    recipient_user_id: str | None = None,
    unfurl_links: bool | None = None,
    unfurl_media: bool | None = None,
    **kwargs) ‑> ChatStream
    +
    +
    +
    + +Expand source code + +
    def chat_stream(
    +    self,
    +    *,
    +    buffer_size: Optional[int] = 256,
    +    channel: str,
    +    thread_ts: str,
    +    recipient_team_id: Optional[str] = None,
    +    recipient_user_id: Optional[str] = None,
    +    unfurl_links: Optional[bool] = None,
    +    unfurl_media: Optional[bool] = None,
    +    **kwargs,
    +) -> ChatStream:
    +    """Stream markdown text into a conversation.
    +
    +    This method provides an easy way to stream markdown text using the following endpoints:
    +    - chat.startStream: Starts a new streaming conversation
    +    - chat.appendStream: Appends text to an existing streaming conversation
    +    - chat.stopStream: Stops a streaming conversation
    +
    +    Args:
    +        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
    +        channel: Channel to stream to
    +        thread_ts: Thread timestamp to stream to (required)
    +        recipient_team_id: Team ID of the recipient (for Slack Connect)
    +        recipient_user_id: User ID of the recipient (for Slack Connect)
    +        unfurl_links: Whether to unfurl links
    +        unfurl_media: Whether to unfurl media
    +        **kwargs: Additional arguments passed to the underlying API calls
    +
    +    Returns:
    +        ChatStreamer instance for managing the stream
    +
    +    Example:
    +        ```python
    +        streamer = client.chat_stream(
    +            channel="C0123456789",
    +            thread_ts="1700000001.123456",
    +            recipient_team_id="T0123456789",
    +            recipient_user_id="U0123456789",
    +        )
    +        streamer.append(markdown_text="**hello wo")
    +        streamer.append(markdown_text="rld!**")
    +        streamer.stop()
    +        ```
    +    """
    +    return ChatStream(
    +        self,
    +        logger=self._logger,
    +        channel=channel,
    +        thread_ts=thread_ts,
    +        recipient_team_id=recipient_team_id,
    +        recipient_user_id=recipient_user_id,
    +        unfurl_links=unfurl_links,
    +        unfurl_media=unfurl_media,
    +        buffer_size=buffer_size,
    +        **kwargs,
    +    )
    +
    +

    Stream markdown text into a conversation.

    +

    This method provides an easy way to stream markdown text using the following endpoints: +- chat.startStream: Starts a new streaming conversation +- chat.appendStream: Appends text to an existing streaming conversation +- chat.stopStream: Stops a streaming conversation

    +

    Args

    +
    +
    buffer_size
    +
    Size of the internal buffer before automatically flushing (default: 256)
    +
    channel
    +
    Channel to stream to
    +
    thread_ts
    +
    Thread timestamp to stream to (required)
    +
    recipient_team_id
    +
    Team ID of the recipient (for Slack Connect)
    +
    recipient_user_id
    +
    User ID of the recipient (for Slack Connect)
    +
    unfurl_links
    +
    Whether to unfurl links
    +
    unfurl_media
    +
    Whether to unfurl media
    +
    **kwargs
    +
    Additional arguments passed to the underlying API calls
    +
    +

    Returns

    +

    ChatStreamer instance for managing the stream

    +

    Example

    +
    streamer = client.chat_stream(
    +    channel="C0123456789",
    +    thread_ts="1700000001.123456",
    +    recipient_team_id="T0123456789",
    +    recipient_user_id="U0123456789",
    +)
    +streamer.append(markdown_text="**hello wo")
    +streamer.append(markdown_text="rld!**")
    +streamer.stop()
    +
    +
    def chat_unfurl(self,
    *,
    channel: str | None = None,
    ts: str | None = None,
    source: str | None = None,
    unfurl_id: str | None = None,
    unfurls: Dict[str, Dict] | None = None,
    user_auth_blocks: str | Sequence[Dict | Block] | None = None,
    user_auth_message: str | None = None,
    user_auth_required: bool | None = None,
    user_auth_url: str | None = None,
    **kwargs) ‑> SlackResponse
    @@ -14961,10 +15131,12 @@

    Inherited members

  • Sub-modules

    • slack_sdk.web.async_base_client
    • +
    • slack_sdk.web.async_chat_stream
    • slack_sdk.web.async_client
    • slack_sdk.web.async_internal_utils
    • slack_sdk.web.async_slack_response
    • slack_sdk.web.base_client
    • +
    • slack_sdk.web.chat_stream
    • slack_sdk.web.client
    • slack_sdk.web.deprecation
    • slack_sdk.web.file_upload_v2_result
    • @@ -15143,6 +15315,7 @@

      Web
    • chat_scheduledMessages_list
    • chat_startStream
    • chat_stopStream
    • +
    • chat_stream
    • chat_unfurl
    • chat_update
    • conversations_acceptSharedInvite
    • diff --git a/docs/reference/web/legacy_client.html b/docs/reference/web/legacy_client.html index 1d4ebbed8..dff0bb98a 100644 --- a/docs/reference/web/legacy_client.html +++ b/docs/reference/web/legacy_client.html @@ -2925,6 +2925,64 @@

      Classes

      kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, @@ -10241,6 +10299,110 @@

      Methods

      Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

      +
      +def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +
      +
      +
      + +Expand source code + +
      def chat_stream(
      +    self,
      +    *,
      +    buffer_size: Optional[int] = 256,
      +    channel: str,
      +    thread_ts: str,
      +    recipient_team_id: Optional[str] = None,
      +    recipient_user_id: Optional[str] = None,
      +    unfurl_links: Optional[bool] = None,
      +    unfurl_media: Optional[bool] = None,
      +    **kwargs,
      +) -> ChatStream:
      +    """Stream markdown text into a conversation.
      +
      +    This method provides an easy way to stream markdown text using the following endpoints:
      +    - chat.startStream: Starts a new streaming conversation
      +    - chat.appendStream: Appends text to an existing streaming conversation
      +    - chat.stopStream: Stops a streaming conversation
      +
      +    Args:
      +        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      +        channel: Channel to stream to
      +        thread_ts: Thread timestamp to stream to (required)
      +        recipient_team_id: Team ID of the recipient (for Slack Connect)
      +        recipient_user_id: User ID of the recipient (for Slack Connect)
      +        unfurl_links: Whether to unfurl links
      +        unfurl_media: Whether to unfurl media
      +        **kwargs: Additional arguments passed to the underlying API calls
      +
      +    Returns:
      +        ChatStreamer instance for managing the stream
      +
      +    Example:
      +        ```python
      +        streamer = client.chat_stream(
      +            channel="C0123456789",
      +            thread_ts="1700000001.123456",
      +            recipient_team_id="T0123456789",
      +            recipient_user_id="U0123456789",
      +        )
      +        streamer.append(markdown_text="**hello wo")
      +        streamer.append(markdown_text="rld!**")
      +        streamer.stop()
      +        ```
      +    """
      +    return ChatStream(
      +        self,
      +        logger=self._logger,
      +        channel=channel,
      +        thread_ts=thread_ts,
      +        recipient_team_id=recipient_team_id,
      +        recipient_user_id=recipient_user_id,
      +        unfurl_links=unfurl_links,
      +        unfurl_media=unfurl_media,
      +        buffer_size=buffer_size,
      +        **kwargs,
      +    )
      +
      +

      Stream markdown text into a conversation.

      +

      This method provides an easy way to stream markdown text using the following endpoints: +- chat.startStream: Starts a new streaming conversation +- chat.appendStream: Appends text to an existing streaming conversation +- chat.stopStream: Stops a streaming conversation

      +

      Args

      +
      +
      buffer_size
      +
      Size of the internal buffer before automatically flushing (default: 256)
      +
      channel
      +
      Channel to stream to
      +
      thread_ts
      +
      Thread timestamp to stream to (required)
      +
      recipient_team_id
      +
      Team ID of the recipient (for Slack Connect)
      +
      recipient_user_id
      +
      User ID of the recipient (for Slack Connect)
      +
      unfurl_links
      +
      Whether to unfurl links
      +
      unfurl_media
      +
      Whether to unfurl media
      +
      **kwargs
      +
      Additional arguments passed to the underlying API calls
      +
      +

      Returns

      +

      ChatStreamer instance for managing the stream

      +

      Example

      +
      streamer = client.chat_stream(
      +    channel="C0123456789",
      +    thread_ts="1700000001.123456",
      +    recipient_team_id="T0123456789",
      +    recipient_user_id="U0123456789",
      +)
      +streamer.append(markdown_text="**hello wo")
      +streamer.append(markdown_text="rld!**")
      +streamer.stop()
      +
      +
      def chat_unfurl(self,
      *,
      channel: str | None = None,
      ts: str | None = None,
      source: str | None = None,
      unfurl_id: str | None = None,
      unfurls: Dict[str, Dict] | None = None,
      user_auth_blocks: str | Sequence[Dict | Block] | None = None,
      user_auth_message: str | None = None,
      user_auth_required: bool | None = None,
      user_auth_url: str | None = None,
      **kwargs) ‑> _asyncio.Future | LegacySlackResponse
      @@ -14756,6 +14918,7 @@

      chat_scheduledMessages_list
    • chat_startStream
    • chat_stopStream
    • +
    • chat_stream
    • chat_unfurl
    • chat_update
    • conversations_acceptSharedInvite
    • diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py new file mode 100644 index 000000000..dfa08cee6 --- /dev/null +++ b/slack_sdk/web/async_chat_stream.py @@ -0,0 +1,166 @@ +import json +import logging +from typing import TYPE_CHECKING, Dict, Optional, Sequence, Union + +import slack_sdk.errors as e +from slack_sdk.models.blocks.blocks import Block +from slack_sdk.models.metadata import Metadata +from slack_sdk.web.async_slack_response import AsyncSlackResponse + +if TYPE_CHECKING: + from slack_sdk.web.async_client import AsyncWebClient + + +class AsyncChatStream: + """A helper class for streaming markdown text into a conversation using the chat streaming APIs. + + This class provides a convenient interface for the chat.startStream, chat.appendStream, + and chat.stopStream API methods, with automatic buffering and state management. + """ + + def __init__( + self, + client: "AsyncWebClient", + *, + channel: str, + logger: logging.Logger, + thread_ts: str, + buffer_size: int, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ): + """Initialize a new ChatStream instance. + + Args: + client: The WebClient instance to use for API calls + channel: Channel ID to stream to + thread_ts: Thread timestamp to stream to + recipient_team_id: Team ID of the recipient + recipient_user_id: User ID of the recipient + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + """ + self._client = client + self._logger = logger + self._stream_args = { + "channel": channel, + "thread_ts": thread_ts, + "recipient_team_id": recipient_team_id, + "recipient_user_id": recipient_user_id, + "unfurl_links": unfurl_links, + "unfurl_media": unfurl_media, + **kwargs, + } + self._buffer = "" + self._state = "starting" + self._stream_ts: Optional[str] = None + self._buffer_size = buffer_size + + async def append( + self, + *, + markdown_text: str, + **kwargs, + ) -> Optional[AsyncSlackResponse]: + """Append markdown text to the stream. + + Args: + markdown_text: The markdown text to append + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + AsyncSlackResponse if the buffer was flushed, None if buffering + + Raises: + SlackRequestError: If the stream is already completed + """ + if self._state == "completed": + raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + self._buffer += markdown_text + if len(self._buffer) >= self._buffer_size: + return await self._flush_buffer(**kwargs) + details = { + "buffer_length": len(self._buffer), + "buffer_size": self._buffer_size, + "channel": self._stream_args.get("channel"), + "recipient_team_id": self._stream_args.get("recipient_team_id"), + "recipient_user_id": self._stream_args.get("recipient_user_id"), + "thread_ts": self._stream_args.get("thread_ts"), + } + self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}") + return None + + async def stop( + self, + *, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> AsyncSlackResponse: + """Stop the stream and finalize the message. + + Args: + markdown_text: Additional markdown text to append before stopping + blocks: Message blocks to add to the final message + metadata: Message metadata to add to the final message + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + AsyncSlackResponse from the chat.stopStream API call + + Raises: + SlackRequestError: If the stream is already completed + """ + if self._state == "completed": + raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if markdown_text: + self._buffer += markdown_text + if not self._stream_ts: + response = await self._client.chat_startStream( + **self._stream_args, + **kwargs, + ) + if not response.get("ts"): + raise e.SlackRequestError("Failed to stop stream: stream not started") + self._stream_ts = str(response["ts"]) + self._state = "in_progress" + + print(f"_stream_args: {self._stream_args}\n") # todo + print(f"_buffer: {self._buffer}\n") + + response = await self._client.chat_stopStream( + channel=self._stream_args["channel"], + ts=self._stream_ts, + blocks=blocks, + markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""), + metadata=metadata, + **kwargs, + ) + self._state = "completed" + return response + + async def _flush_buffer(self, **kwargs) -> AsyncSlackResponse: + """Flush the internal buffer by making appropriate API calls.""" + if not self._stream_ts: + response = await self._client.chat_startStream( + **self._stream_args, + markdown_text=self._buffer, + **kwargs, + ) + self._stream_ts = response.get("ts") + self._state = "in_progress" + else: + response = await self._client.chat_appendStream( + channel=self._stream_args["channel"], + ts=self._stream_ts, + markdown_text=self._buffer, + **kwargs, + ) + + self._buffer = "" + return response diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index 3f30bad5a..dfc9d1868 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -18,6 +18,7 @@ import slack_sdk.errors as e from slack_sdk.models.views import View +from slack_sdk.web.chat_stream import ChatStream from ..models.attachments import Attachment from ..models.blocks import Block @@ -2904,6 +2905,64 @@ async def chat_startStream( kwargs = _remove_none_values(kwargs) return await self.api_call("chat.startStream", json=kwargs) + async def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + async def chat_stopStream( self, *, diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py new file mode 100644 index 000000000..c09311a1b --- /dev/null +++ b/slack_sdk/web/chat_stream.py @@ -0,0 +1,162 @@ +import json +import logging +from typing import TYPE_CHECKING, Dict, Optional, Sequence, Union + +import slack_sdk.errors as e +from slack_sdk.models.blocks.blocks import Block +from slack_sdk.models.metadata import Metadata +from slack_sdk.web.slack_response import SlackResponse + +if TYPE_CHECKING: + from slack_sdk.web.client import WebClient + + +class ChatStream: + """A helper class for streaming markdown text into a conversation using the chat streaming APIs. + + This class provides a convenient interface for the chat.startStream, chat.appendStream, + and chat.stopStream API methods, with automatic buffering and state management. + """ + + def __init__( + self, + client: "WebClient", + *, + channel: str, + logger: logging.Logger, + thread_ts: str, + buffer_size: int, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ): + """Initialize a new ChatStream instance. + + Args: + client: The WebClient instance to use for API calls + channel: Channel ID to stream to + thread_ts: Thread timestamp to stream to + recipient_team_id: Team ID of the recipient + recipient_user_id: User ID of the recipient + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + """ + self._client = client + self._logger = logger + self._stream_args = { + "channel": channel, + "thread_ts": thread_ts, + "recipient_team_id": recipient_team_id, + "recipient_user_id": recipient_user_id, + "unfurl_links": unfurl_links, + "unfurl_media": unfurl_media, + **kwargs, + } + self._buffer = "" + self._state = "starting" + self._stream_ts: Optional[str] = None + self._buffer_size = buffer_size + + def append( + self, + *, + markdown_text: str, + **kwargs, + ) -> Optional[SlackResponse]: + """Append markdown text to the stream. + + Args: + markdown_text: The markdown text to append + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + SlackResponse if the buffer was flushed, None if buffering + + Raises: + SlackRequestError: If the stream is already completed + """ + if self._state == "completed": + raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + self._buffer += markdown_text + if len(self._buffer) >= self._buffer_size: + return self._flush_buffer(**kwargs) + details = { + "buffer_length": len(self._buffer), + "buffer_size": self._buffer_size, + "channel": self._stream_args.get("channel"), + "recipient_team_id": self._stream_args.get("recipient_team_id"), + "recipient_user_id": self._stream_args.get("recipient_user_id"), + "thread_ts": self._stream_args.get("thread_ts"), + } + self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}") + return None + + def stop( + self, + *, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> SlackResponse: + """Stop the stream and finalize the message. + + Args: + markdown_text: Additional markdown text to append before stopping + blocks: Message blocks to add to the final message + metadata: Message metadata to add to the final message + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + SlackResponse from the chat.stopStream API call + + Raises: + SlackRequestError: If the stream is already completed + """ + if self._state == "completed": + raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if markdown_text: + self._buffer += markdown_text + if not self._stream_ts: + response = self._client.chat_startStream( + **self._stream_args, + **kwargs, + ) + if not response.get("ts"): + raise e.SlackRequestError("Failed to stop stream: stream not started") + self._stream_ts = str(response["ts"]) + self._state = "in_progress" + response = self._client.chat_stopStream( + channel=self._stream_args["channel"], + ts=self._stream_ts, + blocks=blocks, + markdown_text=self._buffer, + metadata=metadata, + **kwargs, + ) + self._state = "completed" + return response + + def _flush_buffer(self, **kwargs) -> SlackResponse: + """Flush the internal buffer by making appropriate API calls.""" + if not self._stream_ts: + response = self._client.chat_startStream( + **self._stream_args, + markdown_text=self._buffer, + **kwargs, + ) + self._stream_ts = response.get("ts") + self._state = "in_progress" + else: + response = self._client.chat_appendStream( + channel=self._stream_args["channel"], + ts=self._stream_ts, + markdown_text=self._buffer, + **kwargs, + ) + + self._buffer = "" + return response diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index 8c15f983f..7c500882b 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -8,6 +8,7 @@ import slack_sdk.errors as e from slack_sdk.models.views import View +from slack_sdk.web.chat_stream import ChatStream from ..models.attachments import Attachment from ..models.blocks import Block @@ -2894,6 +2895,64 @@ def chat_startStream( kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, diff --git a/slack_sdk/web/legacy_client.py b/slack_sdk/web/legacy_client.py index 29ef99064..2c2302fec 100644 --- a/slack_sdk/web/legacy_client.py +++ b/slack_sdk/web/legacy_client.py @@ -20,6 +20,7 @@ import slack_sdk.errors as e from slack_sdk.models.views import View +from slack_sdk.web.chat_stream import ChatStream from ..models.attachments import Attachment from ..models.blocks import Block @@ -2906,6 +2907,64 @@ def chat_startStream( kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stream( + self, + *, + buffer_size: Optional[int] = 256, + channel: str, + thread_ts: str, + recipient_team_id: Optional[str] = None, + recipient_user_id: Optional[str] = None, + unfurl_links: Optional[bool] = None, + unfurl_media: Optional[bool] = None, + **kwargs, + ) -> ChatStream: + """Stream markdown text into a conversation. + + This method provides an easy way to stream markdown text using the following endpoints: + - chat.startStream: Starts a new streaming conversation + - chat.appendStream: Appends text to an existing streaming conversation + - chat.stopStream: Stops a streaming conversation + + Args: + buffer_size: Size of the internal buffer before automatically flushing (default: 256) + channel: Channel to stream to + thread_ts: Thread timestamp to stream to (required) + recipient_team_id: Team ID of the recipient (for Slack Connect) + recipient_user_id: User ID of the recipient (for Slack Connect) + unfurl_links: Whether to unfurl links + unfurl_media: Whether to unfurl media + **kwargs: Additional arguments passed to the underlying API calls + + Returns: + ChatStreamer instance for managing the stream + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` + """ + return ChatStream( + self, + logger=self._logger, + channel=channel, + thread_ts=thread_ts, + recipient_team_id=recipient_team_id, + recipient_user_id=recipient_user_id, + unfurl_links=unfurl_links, + unfurl_media=unfurl_media, + buffer_size=buffer_size, + **kwargs, + ) + def chat_stopStream( self, *, diff --git a/tests/slack_sdk/web/test_chat_stream.py b/tests/slack_sdk/web/test_chat_stream.py new file mode 100644 index 000000000..d7b6a223e --- /dev/null +++ b/tests/slack_sdk/web/test_chat_stream.py @@ -0,0 +1,142 @@ +import json +import re +import unittest +from urllib.parse import parse_qs, urlparse + +from slack_sdk import WebClient +from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server +from tests.slack_sdk.web.mock_web_api_handler import MockHandler + + +class ChatStreamMockHandler(MockHandler): + """Extended mock handler that captures request bodies for chat stream methods""" + + def _handle(self): + try: + # put_nowait is common between Queue & asyncio.Queue, it does not need to be awaited + self.server.queue.put_nowait(self.path) + + # Standard auth and validation from parent + if self.is_valid_token() and self.is_valid_user_agent(): + parsed_path = urlparse(self.path) + len_header = self.headers.get("Content-Length") or 0 + content_len = int(len_header) + post_body = self.rfile.read(content_len) + request_body = None + if post_body: + try: + post_body = post_body.decode("utf-8") + if post_body.startswith("{"): + request_body = json.loads(post_body) + else: + request_body = {k: v[0] for k, v in parse_qs(post_body).items()} + except UnicodeDecodeError: + pass + else: + if parsed_path and parsed_path.query: + request_body = {k: v[0] for k, v in parse_qs(parsed_path.query).items()} + + # Store request body for chat stream endpoints + if self.path in ["/chat.startStream", "/chat.appendStream", "/chat.stopStream"] and request_body: + if not hasattr(self.server, "chat_stream_requests"): + self.server.chat_stream_requests = {} + self.server.chat_stream_requests[self.path] = request_body + + # Get token pattern for response file + header = self.headers["authorization"] + pattern = str(header).split("xoxb-", 1)[1] + + # Load response file + with open(f"tests/slack_sdk_fixture/web_response_{pattern}.json") as file: + body = json.load(file) + + else: + body = self.invalid_auth + + if not body: + body = self.not_found + + self.send_response(200) + self.set_common_headers() + self.wfile.write(json.dumps(body).encode("utf-8")) + self.wfile.close() + + except Exception as e: + self.logger.error(str(e), exc_info=True) + raise + + +class TestChatStream(unittest.TestCase): + def setUp(self): + setup_mock_web_api_server(self, ChatStreamMockHandler) + self.client = WebClient( + token="xoxb-chat_stream_test", + base_url="http://localhost:8888", + ) + + def tearDown(self): + cleanup_mock_web_api_server(self) + + pattern_for_language = re.compile("python/(\\S+)", re.IGNORECASE) + pattern_for_package_identifier = re.compile("slackclient/(\\S+)") + + def test_streams_a_short_message(self): + streamer = self.client.chat_stream( + channel="C0123456789", + thread_ts="123.000", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="nice!") + streamer.stop() + + self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 0) + self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) + if hasattr(self.thread.server, "chat_stream_requests"): + start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) + self.assertEqual(start_request.get("channel"), "C0123456789") + self.assertEqual(start_request.get("thread_ts"), "123.000") + self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") + self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") + + stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual(stop_request.get("channel"), "C0123456789") + self.assertEqual(stop_request.get("ts"), "123.123") + self.assertEqual(stop_request.get("markdown_text"), "nice!") + + def test_streams_a_long_message(self): + streamer = self.client.chat_stream( + buffer_size=5, + channel="C0123456789", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + thread_ts="123.000", + ) + streamer.append(markdown_text="**this messag") + streamer.append(markdown_text="e is") + streamer.append(markdown_text=" bold!") + streamer.append(markdown_text="*") + streamer.stop(markdown_text="*") + + self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) + + if hasattr(self.thread.server, "chat_stream_requests"): + start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) + self.assertEqual(start_request.get("channel"), "C0123456789") + self.assertEqual(start_request.get("thread_ts"), "123.000") + self.assertEqual(start_request.get("markdown_text"), "**this messag") + self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") + self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") + + append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {}) + self.assertEqual(append_request.get("channel"), "C0123456789") + self.assertEqual(append_request.get("markdown_text"), "e is bold!") + self.assertEqual(append_request.get("ts"), "123.123") + + stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual(stop_request.get("channel"), "C0123456789") + self.assertEqual(stop_request.get("markdown_text"), "**") + self.assertEqual(stop_request.get("ts"), "123.123") diff --git a/tests/slack_sdk_fixture/web_response_chat_stream_test.json b/tests/slack_sdk_fixture/web_response_chat_stream_test.json new file mode 100644 index 000000000..2b5f29d01 --- /dev/null +++ b/tests/slack_sdk_fixture/web_response_chat_stream_test.json @@ -0,0 +1,4 @@ +{ + "ok": true, + "ts": "123.123" +} From cba64c1276fa730d38f1f23a9beb812f50830022 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 11:48:28 -0700 Subject: [PATCH 02/18] fix: override the token if provided in append or stop methods --- slack_sdk/web/async_chat_stream.py | 20 ++++++++++++-------- slack_sdk/web/chat_stream.py | 14 +++++++++++--- tests/slack_sdk/web/test_chat_stream.py | 15 +++++++++------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py index dfa08cee6..07382e4f3 100644 --- a/slack_sdk/web/async_chat_stream.py +++ b/slack_sdk/web/async_chat_stream.py @@ -58,6 +58,7 @@ def __init__( self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None + self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size async def append( @@ -80,6 +81,8 @@ async def append( """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return await self._flush_buffer(**kwargs) @@ -118,26 +121,25 @@ async def stop( """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = await self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" - - print(f"_stream_args: {self._stream_args}\n") # todo - print(f"_buffer: {self._buffer}\n") - response = await self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, - markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""), + markdown_text=self._buffer, metadata=metadata, **kwargs, ) @@ -149,17 +151,19 @@ async def _flush_buffer(self, **kwargs) -> AsyncSlackResponse: if not self._stream_ts: response = await self._client.chat_startStream( **self._stream_args, - markdown_text=self._buffer, + token=self._token, **kwargs, + markdown_text=self._buffer, ) self._stream_ts = response.get("ts") self._state = "in_progress" else: response = await self._client.chat_appendStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, - markdown_text=self._buffer, **kwargs, + markdown_text=self._buffer, ) self._buffer = "" diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py index c09311a1b..863a08dcc 100644 --- a/slack_sdk/web/chat_stream.py +++ b/slack_sdk/web/chat_stream.py @@ -58,6 +58,7 @@ def __init__( self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None + self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size def append( @@ -80,6 +81,8 @@ def append( """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return self._flush_buffer(**kwargs) @@ -118,18 +121,21 @@ def stop( """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" response = self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, @@ -145,17 +151,19 @@ def _flush_buffer(self, **kwargs) -> SlackResponse: if not self._stream_ts: response = self._client.chat_startStream( **self._stream_args, - markdown_text=self._buffer, + token=self._token, **kwargs, + markdown_text=self._buffer, ) self._stream_ts = response.get("ts") self._state = "in_progress" else: response = self._client.chat_appendStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, - markdown_text=self._buffer, **kwargs, + markdown_text=self._buffer, ) self._buffer = "" diff --git a/tests/slack_sdk/web/test_chat_stream.py b/tests/slack_sdk/web/test_chat_stream.py index d7b6a223e..5b0ecee87 100644 --- a/tests/slack_sdk/web/test_chat_stream.py +++ b/tests/slack_sdk/web/test_chat_stream.py @@ -18,6 +18,7 @@ def _handle(self): # Standard auth and validation from parent if self.is_valid_token() and self.is_valid_user_agent(): + token = self.headers["authorization"].split(" ")[1] parsed_path = urlparse(self.path) len_header = self.headers.get("Content-Length") or 0 content_len = int(len_header) @@ -40,13 +41,13 @@ def _handle(self): if self.path in ["/chat.startStream", "/chat.appendStream", "/chat.stopStream"] and request_body: if not hasattr(self.server, "chat_stream_requests"): self.server.chat_stream_requests = {} - self.server.chat_stream_requests[self.path] = request_body - - # Get token pattern for response file - header = self.headers["authorization"] - pattern = str(header).split("xoxb-", 1)[1] + self.server.chat_stream_requests[self.path] = { + "token": token, + **request_body, + } # Load response file + pattern = str(token).split("xoxb-", 1)[1] with open(f"tests/slack_sdk_fixture/web_response_{pattern}.json") as file: body = json.load(file) @@ -93,6 +94,7 @@ def test_streams_a_short_message(self): self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 0) self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) + if hasattr(self.thread.server, "chat_stream_requests"): start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) self.assertEqual(start_request.get("channel"), "C0123456789") @@ -117,7 +119,7 @@ def test_streams_a_long_message(self): streamer.append(markdown_text="e is") streamer.append(markdown_text=" bold!") streamer.append(markdown_text="*") - streamer.stop(markdown_text="*") + streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token") self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) @@ -139,4 +141,5 @@ def test_streams_a_long_message(self): stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) self.assertEqual(stop_request.get("channel"), "C0123456789") self.assertEqual(stop_request.get("markdown_text"), "**") + self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token") self.assertEqual(stop_request.get("ts"), "123.123") From 99cccd1e49a4ec88a70c7437648fa811567271fb Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 11:49:17 -0700 Subject: [PATCH 03/18] fix: codegen async --- scripts/codegen.py | 19 ++++++++++++++++++- slack_sdk/web/async_client.py | 12 ++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/scripts/codegen.py b/scripts/codegen.py index f58de8bd1..1829be664 100644 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -1,5 +1,5 @@ -import sys import argparse +import sys parser = argparse.ArgumentParser() parser.add_argument("-p", "--path", help="Path to the project source code.", type=str) @@ -47,6 +47,23 @@ async_source, ) async_source = re.sub(r"= WebClient\(", "= AsyncWebClient(", async_source) + async_source = re.sub( + "from slack_sdk.web.chat_stream import ChatStream", + "from slack_sdk.web.async_chat_stream import AsyncChatStream", + async_source, + ) + async_source = re.sub(r"ChatStream:", "AsyncChatStream:", async_source) + async_source = re.sub(r"ChatStream\(", "AsyncChatStream(", async_source) + async_source = re.sub( + r" streamer.append\(", + " await streamer.append(", + async_source, + ) + async_source = re.sub( + r" streamer.stop\(", + " await streamer.stop(", + async_source, + ) async_source = re.sub( r" self.files_getUploadURLExternal\(", " await self.files_getUploadURLExternal(", diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index dfc9d1868..87c14ee3e 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -18,7 +18,7 @@ import slack_sdk.errors as e from slack_sdk.models.views import View -from slack_sdk.web.chat_stream import ChatStream +from slack_sdk.web.async_chat_stream import AsyncChatStream from ..models.attachments import Attachment from ..models.blocks import Block @@ -2916,7 +2916,7 @@ async def chat_stream( unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, **kwargs, - ) -> ChatStream: + ) -> AsyncChatStream: """Stream markdown text into a conversation. This method provides an easy way to stream markdown text using the following endpoints: @@ -2945,12 +2945,12 @@ async def chat_stream( recipient_team_id="T0123456789", recipient_user_id="U0123456789", ) - streamer.append(markdown_text="**hello wo") - streamer.append(markdown_text="rld!**") - streamer.stop() + await streamer.append(markdown_text="**hello wo") + await streamer.append(markdown_text="rld!**") + await streamer.stop() ``` """ - return ChatStream( + return AsyncChatStream( self, logger=self._logger, channel=channel, From ee255369cc8148f002288f968df6d577bbfa46fa Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 11:49:32 -0700 Subject: [PATCH 04/18] fix: remove optional arguments with a default --- slack_sdk/web/async_client.py | 2 +- slack_sdk/web/client.py | 2 +- slack_sdk/web/legacy_client.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index 87c14ee3e..8b3a406f5 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -2908,7 +2908,7 @@ async def chat_startStream( async def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index 7c500882b..a1afb6f8c 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -2898,7 +2898,7 @@ def chat_startStream( def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, diff --git a/slack_sdk/web/legacy_client.py b/slack_sdk/web/legacy_client.py index 2c2302fec..a8aac3602 100644 --- a/slack_sdk/web/legacy_client.py +++ b/slack_sdk/web/legacy_client.py @@ -2910,7 +2910,7 @@ def chat_startStream( def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, From af7bea26b196ac25092f3ee5d909d54da3711eb7 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 11:58:55 -0700 Subject: [PATCH 05/18] test: confirm async implementation matches sync --- .../web/test_async_chat_stream.py | 148 ++++++++++++++++++ .../web_response_chat_stream_test_token.json | 3 + 2 files changed, 151 insertions(+) create mode 100644 tests/slack_sdk_async/web/test_async_chat_stream.py create mode 100644 tests/slack_sdk_fixture/web_response_chat_stream_test_token.json diff --git a/tests/slack_sdk_async/web/test_async_chat_stream.py b/tests/slack_sdk_async/web/test_async_chat_stream.py new file mode 100644 index 000000000..01c564ded --- /dev/null +++ b/tests/slack_sdk_async/web/test_async_chat_stream.py @@ -0,0 +1,148 @@ +import json +import re +import unittest +from urllib.parse import parse_qs, urlparse + +from slack_sdk.web.async_client import AsyncWebClient +from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server +from tests.slack_sdk.web.mock_web_api_handler import MockHandler +from tests.slack_sdk_async.helpers import async_test + + +class ChatStreamMockHandler(MockHandler): + """Extended mock handler that captures request bodies for chat stream methods""" + + def _handle(self): + try: + # put_nowait is common between Queue & asyncio.Queue, it does not need to be awaited + self.server.queue.put_nowait(self.path) + + # Standard auth and validation from parent + if self.is_valid_token() and self.is_valid_user_agent(): + token = self.headers["authorization"].split(" ")[1] + parsed_path = urlparse(self.path) + len_header = self.headers.get("Content-Length") or 0 + content_len = int(len_header) + post_body = self.rfile.read(content_len) + request_body = None + if post_body: + try: + post_body = post_body.decode("utf-8") + if post_body.startswith("{"): + request_body = json.loads(post_body) + else: + request_body = {k: v[0] for k, v in parse_qs(post_body).items()} + except UnicodeDecodeError: + pass + else: + if parsed_path and parsed_path.query: + request_body = {k: v[0] for k, v in parse_qs(parsed_path.query).items()} + + # Store request body for chat stream endpoints + if self.path in ["/chat.startStream", "/chat.appendStream", "/chat.stopStream"] and request_body: + if not hasattr(self.server, "chat_stream_requests"): + self.server.chat_stream_requests = {} + self.server.chat_stream_requests[self.path] = { + "token": token, + **request_body, + } + + # Load response file + pattern = str(token).split("xoxb-", 1)[1] + with open(f"tests/slack_sdk_fixture/web_response_{pattern}.json") as file: + body = json.load(file) + + else: + body = self.invalid_auth + + if not body: + body = self.not_found + + self.send_response(200) + self.set_common_headers() + self.wfile.write(json.dumps(body).encode("utf-8")) + self.wfile.close() + + except Exception as e: + self.logger.error(str(e), exc_info=True) + raise + + +class TestAsyncChatStream(unittest.TestCase): + def setUp(self): + setup_mock_web_api_server(self, ChatStreamMockHandler) + self.client = AsyncWebClient( + token="xoxb-chat_stream_test", + base_url="http://localhost:8888", + ) + + def tearDown(self): + cleanup_mock_web_api_server(self) + + pattern_for_language = re.compile("python/(\\S+)", re.IGNORECASE) + pattern_for_package_identifier = re.compile("slackclient/(\\S+)") + + @async_test + async def test_streams_a_short_message(self): + streamer = await self.client.chat_stream( + channel="C0123456789", + thread_ts="123.000", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + await streamer.append(markdown_text="nice!") + await streamer.stop() + + self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 0) + self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) + + if hasattr(self.thread.server, "chat_stream_requests"): + start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) + self.assertEqual(start_request.get("channel"), "C0123456789") + self.assertEqual(start_request.get("thread_ts"), "123.000") + self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") + self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") + + stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual(stop_request.get("channel"), "C0123456789") + self.assertEqual(stop_request.get("ts"), "123.123") + self.assertEqual(stop_request.get("markdown_text"), "nice!") + + @async_test + async def test_streams_a_long_message(self): + streamer = await self.client.chat_stream( + buffer_size=5, + channel="C0123456789", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + thread_ts="123.000", + ) + await streamer.append(markdown_text="**this messag") + await streamer.append(markdown_text="e is") + await streamer.append(markdown_text=" bold!") + await streamer.append(markdown_text="*") + await streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token") + + self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) + self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) + + if hasattr(self.thread.server, "chat_stream_requests"): + start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) + self.assertEqual(start_request.get("channel"), "C0123456789") + self.assertEqual(start_request.get("thread_ts"), "123.000") + self.assertEqual(start_request.get("markdown_text"), "**this messag") + self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") + self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") + + append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {}) + self.assertEqual(append_request.get("channel"), "C0123456789") + self.assertEqual(append_request.get("markdown_text"), "e is bold!") + self.assertEqual(append_request.get("ts"), "123.123") + + stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual(stop_request.get("channel"), "C0123456789") + self.assertEqual(stop_request.get("markdown_text"), "**") + self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token") + self.assertEqual(stop_request.get("ts"), "123.123") diff --git a/tests/slack_sdk_fixture/web_response_chat_stream_test_token.json b/tests/slack_sdk_fixture/web_response_chat_stream_test_token.json new file mode 100644 index 000000000..0287aedde --- /dev/null +++ b/tests/slack_sdk_fixture/web_response_chat_stream_test_token.json @@ -0,0 +1,3 @@ +{ + "ok": true +} From fe40900e2b86bdca547100d83ac5edcc73cbdc82 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 12:00:43 -0700 Subject: [PATCH 06/18] docs: match async setups in testing --- scripts/codegen.py | 5 +++++ slack_sdk/web/async_client.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/codegen.py b/scripts/codegen.py index 1829be664..d665fa322 100644 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -54,6 +54,11 @@ ) async_source = re.sub(r"ChatStream:", "AsyncChatStream:", async_source) async_source = re.sub(r"ChatStream\(", "AsyncChatStream(", async_source) + async_source = re.sub( + r" client.chat_stream\(", + " await client.chat_stream(", + async_source, + ) async_source = re.sub( r" streamer.append\(", " await streamer.append(", diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index 8b3a406f5..bb776efb7 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -2939,7 +2939,7 @@ async def chat_stream( Example: ```python - streamer = client.chat_stream( + streamer = await client.chat_stream( channel="C0123456789", thread_ts="1700000001.123456", recipient_team_id="T0123456789", From 557681bb1786fedfe18fe8dd705618cfe202f23f Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 12:36:02 -0700 Subject: [PATCH 07/18] chore: autogenerate the async chat stream helper --- scripts/codegen.py | 29 ++++++++++++++++++++++++++++- slack_sdk/web/async_chat_stream.py | 10 ++++++++++ slack_sdk/web/chat_stream.py | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/scripts/codegen.py b/scripts/codegen.py index d665fa322..9bff4e474 100644 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -35,7 +35,6 @@ "from .async_base_client import AsyncBaseClient, AsyncSlackResponse", async_source, ) - # from slack_sdk import WebClient async_source = re.sub( r"class WebClient\(BaseClient\):", "class AsyncWebClient(AsyncBaseClient):", @@ -122,3 +121,31 @@ legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source) with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output: output.write(legacy_source) + +with open(f"{args.path}/slack_sdk/web/chat_stream.py", "r") as original: + source = original.read() + import re + + async_source = header + source + async_source = re.sub( + "from slack_sdk.web.slack_response import SlackResponse", + "from slack_sdk.web.async_slack_response import AsyncSlackResponse", + async_source, + ) + async_source = re.sub( + r"from slack_sdk import WebClient", + "from slack_sdk.web.async_client import AsyncWebClient", + async_source, + ) + async_source = re.sub("class ChatStream", "class AsyncChatStream", async_source) + async_source = re.sub('"WebClient"', '"AsyncWebClient"', async_source) + async_source = re.sub(r"Optional\[SlackResponse\]", "Optional[AsyncSlackResponse]", async_source) + async_source = re.sub(r"SlackResponse ", "AsyncSlackResponse ", async_source) + async_source = re.sub(r"SlackResponse:", "AsyncSlackResponse:", async_source) + async_source = re.sub(r"def append\(", "async def append(", async_source) + async_source = re.sub(r"def stop\(", "async def stop(", async_source) + async_source = re.sub(r"def _flush_buffer\(", "async def _flush_buffer(", async_source) + async_source = re.sub("self._client.chat_", "await self._client.chat_", async_source) + async_source = re.sub("self._flush_buffer", "await self._flush_buffer", async_source) + with open(f"{args.path}/slack_sdk/web/async_chat_stream.py", "w") as output: + output.write(async_source) diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py index 07382e4f3..ccf7b1969 100644 --- a/slack_sdk/web/async_chat_stream.py +++ b/slack_sdk/web/async_chat_stream.py @@ -1,3 +1,13 @@ +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# +# *** DO NOT EDIT THIS FILE *** +# +# 1) Modify slack_sdk/web/client.py +# 2) Run `python scripts/codegen.py` +# 3) Run `black slack_sdk/` +# +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + import json import logging from typing import TYPE_CHECKING, Dict, Optional, Sequence, Union diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py index 863a08dcc..6923fba98 100644 --- a/slack_sdk/web/chat_stream.py +++ b/slack_sdk/web/chat_stream.py @@ -8,7 +8,7 @@ from slack_sdk.web.slack_response import SlackResponse if TYPE_CHECKING: - from slack_sdk.web.client import WebClient + from slack_sdk import WebClient class ChatStream: From 64f4b1409b7142e53ecbb07bf83587a306c4b06f Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 12:36:49 -0700 Subject: [PATCH 08/18] docs: autogenerate reference --- docs/reference/index.html | 6 ++-- docs/reference/web/async_chat_stream.html | 33 +++++++++++--------- docs/reference/web/async_client.html | 38 +++++++++++------------ docs/reference/web/chat_stream.html | 21 ++++++++++--- docs/reference/web/client.html | 6 ++-- docs/reference/web/index.html | 6 ++-- docs/reference/web/legacy_client.html | 6 ++-- 7 files changed, 67 insertions(+), 49 deletions(-) diff --git a/docs/reference/index.html b/docs/reference/index.html index 6cd8cbbeb..ce7b50c45 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -3033,7 +3033,7 @@

      Classes

      def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, @@ -10405,7 +10405,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      @@ -10415,7 +10415,7 @@

      Methods

      def chat_stream(
           self,
           *,
      -    buffer_size: Optional[int] = 256,
      +    buffer_size: int = 256,
           channel: str,
           thread_ts: str,
           recipient_team_id: Optional[str] = None,
      diff --git a/docs/reference/web/async_chat_stream.html b/docs/reference/web/async_chat_stream.html
      index 8c7900814..cf5db2979 100644
      --- a/docs/reference/web/async_chat_stream.html
      +++ b/docs/reference/web/async_chat_stream.html
      @@ -102,6 +102,7 @@ 

      Classes

      self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None + self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size async def append( @@ -124,6 +125,8 @@

      Classes

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return await self._flush_buffer(**kwargs) @@ -162,26 +165,25 @@

      Classes

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = await self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" - - print(f"_stream_args: {self._stream_args}\n") # todo - print(f"_buffer: {self._buffer}\n") - response = await self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, - markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""), + markdown_text=self._buffer, metadata=metadata, **kwargs, ) @@ -193,17 +195,19 @@

      Classes

      if not self._stream_ts: response = await self._client.chat_startStream( **self._stream_args, - markdown_text=self._buffer, + token=self._token, **kwargs, + markdown_text=self._buffer, ) self._stream_ts = response.get("ts") self._state = "in_progress" else: response = await self._client.chat_appendStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, - markdown_text=self._buffer, **kwargs, + markdown_text=self._buffer, ) self._buffer = "" @@ -262,6 +266,8 @@

      Methods

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return await self._flush_buffer(**kwargs) @@ -324,26 +330,25 @@

      Raises

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = await self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" - - print(f"_stream_args: {self._stream_args}\n") # todo - print(f"_buffer: {self._buffer}\n") - response = await self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, - markdown_text=self._buffer + (markdown_text if markdown_text is not None else ""), + markdown_text=self._buffer, metadata=metadata, **kwargs, ) diff --git a/docs/reference/web/async_client.html b/docs/reference/web/async_client.html index 3ee659eb4..66cf63ad4 100644 --- a/docs/reference/web/async_client.html +++ b/docs/reference/web/async_client.html @@ -2929,7 +2929,7 @@

      Classes

      async def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, @@ -2937,7 +2937,7 @@

      Classes

      unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, **kwargs, - ) -> ChatStream: + ) -> AsyncChatStream: """Stream markdown text into a conversation. This method provides an easy way to stream markdown text using the following endpoints: @@ -2960,18 +2960,18 @@

      Classes

      Example: ```python - streamer = client.chat_stream( + streamer = await client.chat_stream( channel="C0123456789", thread_ts="1700000001.123456", recipient_team_id="T0123456789", recipient_user_id="U0123456789", ) - streamer.append(markdown_text="**hello wo") - streamer.append(markdown_text="rld!**") - streamer.stop() + await streamer.append(markdown_text="**hello wo") + await streamer.append(markdown_text="rld!**") + await streamer.stop() ``` """ - return ChatStream( + return AsyncChatStream( self, logger=self._logger, channel=channel, @@ -10301,7 +10301,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -async def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +async def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> AsyncChatStream
      @@ -10311,7 +10311,7 @@

      Methods

      async def chat_stream(
           self,
           *,
      -    buffer_size: Optional[int] = 256,
      +    buffer_size: int = 256,
           channel: str,
           thread_ts: str,
           recipient_team_id: Optional[str] = None,
      @@ -10319,7 +10319,7 @@ 

      Methods

      unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, **kwargs, -) -> ChatStream: +) -> AsyncChatStream: """Stream markdown text into a conversation. This method provides an easy way to stream markdown text using the following endpoints: @@ -10342,18 +10342,18 @@

      Methods

      Example: ```python - streamer = client.chat_stream( + streamer = await client.chat_stream( channel="C0123456789", thread_ts="1700000001.123456", recipient_team_id="T0123456789", recipient_user_id="U0123456789", ) - streamer.append(markdown_text="**hello wo") - streamer.append(markdown_text="rld!**") - streamer.stop() + await streamer.append(markdown_text="**hello wo") + await streamer.append(markdown_text="rld!**") + await streamer.stop() ``` """ - return ChatStream( + return AsyncChatStream( self, logger=self._logger, channel=channel, @@ -10393,15 +10393,15 @@

      Args

      Returns

      ChatStreamer instance for managing the stream

      Example

      -
      streamer = client.chat_stream(
      +
      streamer = await client.chat_stream(
           channel="C0123456789",
           thread_ts="1700000001.123456",
           recipient_team_id="T0123456789",
           recipient_user_id="U0123456789",
       )
      -streamer.append(markdown_text="**hello wo")
      -streamer.append(markdown_text="rld!**")
      -streamer.stop()
      +await streamer.append(markdown_text="**hello wo")
      +await streamer.append(markdown_text="rld!**")
      +await streamer.stop()
       
      diff --git a/docs/reference/web/chat_stream.html b/docs/reference/web/chat_stream.html index c23ae4343..434a5794b 100644 --- a/docs/reference/web/chat_stream.html +++ b/docs/reference/web/chat_stream.html @@ -102,6 +102,7 @@

      Classes

      self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None + self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size def append( @@ -124,6 +125,8 @@

      Classes

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return self._flush_buffer(**kwargs) @@ -162,18 +165,21 @@

      Classes

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" response = self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, @@ -189,17 +195,19 @@

      Classes

      if not self._stream_ts: response = self._client.chat_startStream( **self._stream_args, - markdown_text=self._buffer, + token=self._token, **kwargs, + markdown_text=self._buffer, ) self._stream_ts = response.get("ts") self._state = "in_progress" else: response = self._client.chat_appendStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, - markdown_text=self._buffer, **kwargs, + markdown_text=self._buffer, ) self._buffer = "" @@ -258,6 +266,8 @@

      Methods

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") self._buffer += markdown_text if len(self._buffer) >= self._buffer_size: return self._flush_buffer(**kwargs) @@ -320,18 +330,21 @@

      Raises

      """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") + if kwargs.get("token"): + self._token = kwargs.pop("token") if markdown_text: self._buffer += markdown_text if not self._stream_ts: response = self._client.chat_startStream( **self._stream_args, - **kwargs, + token=self._token, ) if not response.get("ts"): raise e.SlackRequestError("Failed to stop stream: stream not started") self._stream_ts = str(response["ts"]) self._state = "in_progress" response = self._client.chat_stopStream( + token=self._token, channel=self._stream_args["channel"], ts=self._stream_ts, blocks=blocks, diff --git a/docs/reference/web/client.html b/docs/reference/web/client.html index 0ad9ca23b..b28f6e956 100644 --- a/docs/reference/web/client.html +++ b/docs/reference/web/client.html @@ -2929,7 +2929,7 @@

      Classes

      def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, @@ -10301,7 +10301,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      @@ -10311,7 +10311,7 @@

      Methods

      def chat_stream(
           self,
           *,
      -    buffer_size: Optional[int] = 256,
      +    buffer_size: int = 256,
           channel: str,
           thread_ts: str,
           recipient_team_id: Optional[str] = None,
      diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html
      index 38087d56f..6fccde48a 100644
      --- a/docs/reference/web/index.html
      +++ b/docs/reference/web/index.html
      @@ -3298,7 +3298,7 @@ 

      Raises

      def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, @@ -10670,7 +10670,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      @@ -10680,7 +10680,7 @@

      Methods

      def chat_stream(
           self,
           *,
      -    buffer_size: Optional[int] = 256,
      +    buffer_size: int = 256,
           channel: str,
           thread_ts: str,
           recipient_team_id: Optional[str] = None,
      diff --git a/docs/reference/web/legacy_client.html b/docs/reference/web/legacy_client.html
      index dff0bb98a..79583d84d 100644
      --- a/docs/reference/web/legacy_client.html
      +++ b/docs/reference/web/legacy_client.html
      @@ -2928,7 +2928,7 @@ 

      Classes

      def chat_stream( self, *, - buffer_size: Optional[int] = 256, + buffer_size: int = 256, channel: str, thread_ts: str, recipient_team_id: Optional[str] = None, @@ -10300,7 +10300,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int | None = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      @@ -10310,7 +10310,7 @@

      Methods

      def chat_stream(
           self,
           *,
      -    buffer_size: Optional[int] = 256,
      +    buffer_size: int = 256,
           channel: str,
           thread_ts: str,
           recipient_team_id: Optional[str] = None,
      
      From 03566bd0c2cf1fe9131e42bdfd78a709a088ef65 Mon Sep 17 00:00:00 2001
      From: Eden Zimbelman 
      Date: Wed, 1 Oct 2025 14:33:23 -0700
      Subject: [PATCH 09/18] feat: remove legacy implementation
      
      ---
       docs/reference/web/legacy_client.html | 163 --------------------------
       scripts/codegen.py                    |   2 +
       slack_sdk/web/legacy_client.py        |  60 +---------
       3 files changed, 3 insertions(+), 222 deletions(-)
      
      diff --git a/docs/reference/web/legacy_client.html b/docs/reference/web/legacy_client.html
      index 79583d84d..1d4ebbed8 100644
      --- a/docs/reference/web/legacy_client.html
      +++ b/docs/reference/web/legacy_client.html
      @@ -2925,64 +2925,6 @@ 

      Classes

      kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) - def chat_stream( - self, - *, - buffer_size: int = 256, - channel: str, - thread_ts: str, - recipient_team_id: Optional[str] = None, - recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, - **kwargs, - ) -> ChatStream: - """Stream markdown text into a conversation. - - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation - - Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls - - Returns: - ChatStreamer instance for managing the stream - - Example: - ```python - streamer = client.chat_stream( - channel="C0123456789", - thread_ts="1700000001.123456", - recipient_team_id="T0123456789", - recipient_user_id="U0123456789", - ) - streamer.append(markdown_text="**hello wo") - streamer.append(markdown_text="rld!**") - streamer.stop() - ``` - """ - return ChatStream( - self, - logger=self._logger, - channel=channel, - thread_ts=thread_ts, - recipient_team_id=recipient_team_id, - recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, - buffer_size=buffer_size, - **kwargs, - ) - def chat_stopStream( self, *, @@ -10299,110 +10241,6 @@

      Methods

      Stops a streaming conversation. https://api.slack.com/methods/chat.stopStream

      -
      -def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      -
      -
      -
      - -Expand source code - -
      def chat_stream(
      -    self,
      -    *,
      -    buffer_size: int = 256,
      -    channel: str,
      -    thread_ts: str,
      -    recipient_team_id: Optional[str] = None,
      -    recipient_user_id: Optional[str] = None,
      -    unfurl_links: Optional[bool] = None,
      -    unfurl_media: Optional[bool] = None,
      -    **kwargs,
      -) -> ChatStream:
      -    """Stream markdown text into a conversation.
      -
      -    This method provides an easy way to stream markdown text using the following endpoints:
      -    - chat.startStream: Starts a new streaming conversation
      -    - chat.appendStream: Appends text to an existing streaming conversation
      -    - chat.stopStream: Stops a streaming conversation
      -
      -    Args:
      -        buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      -        channel: Channel to stream to
      -        thread_ts: Thread timestamp to stream to (required)
      -        recipient_team_id: Team ID of the recipient (for Slack Connect)
      -        recipient_user_id: User ID of the recipient (for Slack Connect)
      -        unfurl_links: Whether to unfurl links
      -        unfurl_media: Whether to unfurl media
      -        **kwargs: Additional arguments passed to the underlying API calls
      -
      -    Returns:
      -        ChatStreamer instance for managing the stream
      -
      -    Example:
      -        ```python
      -        streamer = client.chat_stream(
      -            channel="C0123456789",
      -            thread_ts="1700000001.123456",
      -            recipient_team_id="T0123456789",
      -            recipient_user_id="U0123456789",
      -        )
      -        streamer.append(markdown_text="**hello wo")
      -        streamer.append(markdown_text="rld!**")
      -        streamer.stop()
      -        ```
      -    """
      -    return ChatStream(
      -        self,
      -        logger=self._logger,
      -        channel=channel,
      -        thread_ts=thread_ts,
      -        recipient_team_id=recipient_team_id,
      -        recipient_user_id=recipient_user_id,
      -        unfurl_links=unfurl_links,
      -        unfurl_media=unfurl_media,
      -        buffer_size=buffer_size,
      -        **kwargs,
      -    )
      -
      -

      Stream markdown text into a conversation.

      -

      This method provides an easy way to stream markdown text using the following endpoints: -- chat.startStream: Starts a new streaming conversation -- chat.appendStream: Appends text to an existing streaming conversation -- chat.stopStream: Stops a streaming conversation

      -

      Args

      -
      -
      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      -
      channel
      -
      Channel to stream to
      -
      thread_ts
      -
      Thread timestamp to stream to (required)
      -
      recipient_team_id
      -
      Team ID of the recipient (for Slack Connect)
      -
      recipient_user_id
      -
      User ID of the recipient (for Slack Connect)
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      -
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      -
      -

      Returns

      -

      ChatStreamer instance for managing the stream

      -

      Example

      -
      streamer = client.chat_stream(
      -    channel="C0123456789",
      -    thread_ts="1700000001.123456",
      -    recipient_team_id="T0123456789",
      -    recipient_user_id="U0123456789",
      -)
      -streamer.append(markdown_text="**hello wo")
      -streamer.append(markdown_text="rld!**")
      -streamer.stop()
      -
      -
      def chat_unfurl(self,
      *,
      channel: str | None = None,
      ts: str | None = None,
      source: str | None = None,
      unfurl_id: str | None = None,
      unfurls: Dict[str, Dict] | None = None,
      user_auth_blocks: str | Sequence[Dict | Block] | None = None,
      user_auth_message: str | None = None,
      user_auth_required: bool | None = None,
      user_auth_url: str | None = None,
      **kwargs) ‑> _asyncio.Future | LegacySlackResponse
      @@ -14918,7 +14756,6 @@

      chat_scheduledMessages_list
    • chat_startStream
    • chat_stopStream
    • -
    • chat_stream
    • chat_unfurl
    • chat_update
    • conversations_acceptSharedInvite
    • diff --git a/scripts/codegen.py b/scripts/codegen.py index 9bff4e474..b23088b5a 100644 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -119,6 +119,8 @@ legacy_source, ) legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source) + legacy_source = re.sub(r"from slack_sdk.web.chat_stream import ChatStream", "", legacy_source) + legacy_source = re.sub(r"(?s)def chat_stream.*?(?=def\s+chat_stopStream\()", "", legacy_source) with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output: output.write(legacy_source) diff --git a/slack_sdk/web/legacy_client.py b/slack_sdk/web/legacy_client.py index a8aac3602..1eeee1f40 100644 --- a/slack_sdk/web/legacy_client.py +++ b/slack_sdk/web/legacy_client.py @@ -20,7 +20,7 @@ import slack_sdk.errors as e from slack_sdk.models.views import View -from slack_sdk.web.chat_stream import ChatStream + from ..models.attachments import Attachment from ..models.blocks import Block @@ -2907,64 +2907,6 @@ def chat_startStream( kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) - def chat_stream( - self, - *, - buffer_size: int = 256, - channel: str, - thread_ts: str, - recipient_team_id: Optional[str] = None, - recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, - **kwargs, - ) -> ChatStream: - """Stream markdown text into a conversation. - - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation - - Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls - - Returns: - ChatStreamer instance for managing the stream - - Example: - ```python - streamer = client.chat_stream( - channel="C0123456789", - thread_ts="1700000001.123456", - recipient_team_id="T0123456789", - recipient_user_id="U0123456789", - ) - streamer.append(markdown_text="**hello wo") - streamer.append(markdown_text="rld!**") - streamer.stop() - ``` - """ - return ChatStream( - self, - logger=self._logger, - channel=channel, - thread_ts=thread_ts, - recipient_team_id=recipient_team_id, - recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, - buffer_size=buffer_size, - **kwargs, - ) - def chat_stopStream( self, *, From 187c71924338ae3349259bbfd7c53d6da727c88a Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 16:22:31 -0700 Subject: [PATCH 10/18] fix: improve docs to match arguments with better testing --- docs/reference/index.html | 93 ++++---- docs/reference/web/async_chat_stream.html | 205 ++++++++++++------ docs/reference/web/async_client.html | 93 ++++---- docs/reference/web/chat_stream.html | 205 ++++++++++++------ docs/reference/web/client.html | 93 ++++---- docs/reference/web/index.html | 93 ++++---- slack_sdk/web/async_chat_stream.py | 78 ++++--- slack_sdk/web/async_client.py | 31 ++- slack_sdk/web/chat_stream.py | 78 ++++--- slack_sdk/web/client.py | 31 ++- tests/slack_sdk/web/test_chat_stream.py | 29 ++- .../web/test_async_chat_stream.py | 31 ++- ...response_chat_stream_test_missing_ts.json} | 0 .../web_response_chat_stream_test_token1.json | 3 + .../web_response_chat_stream_test_token2.json | 3 + 15 files changed, 642 insertions(+), 424 deletions(-) rename tests/slack_sdk_fixture/{web_response_chat_stream_test_token.json => web_response_chat_stream_test_missing_ts.json} (100%) create mode 100644 tests/slack_sdk_fixture/web_response_chat_stream_test_token1.json create mode 100644 tests/slack_sdk_fixture/web_response_chat_stream_test_token2.json diff --git a/docs/reference/index.html b/docs/reference/index.html index ce7b50c45..76fdfb093 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -3038,29 +3038,28 @@

      Classes

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -3082,8 +3081,6 @@

      Classes

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, ) @@ -10405,7 +10402,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs) ‑> ChatStream
      @@ -10420,29 +10417,28 @@

      Methods

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -10464,38 +10460,35 @@

      Methods

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, )

      Stream markdown text into a conversation.

      -

      This method provides an easy way to stream markdown text using the following endpoints: -- chat.startStream: Starts a new streaming conversation -- chat.appendStream: Appends text to an existing streaming conversation -- chat.stopStream: Stops a streaming conversation

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      The following methods are used:

      +
        +
      • chat.startStream: Starts a new streaming conversation. Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +

      Args

      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      channel
      -
      Channel to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Thread timestamp to stream to (required)
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient (for Slack Connect)
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient (for Slack Connect)
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      ChatStreamer instance for managing the stream

      +

      ChatStream instance for managing the stream

      Example

      streamer = client.chat_stream(
           channel="C0123456789",
      diff --git a/docs/reference/web/async_chat_stream.html b/docs/reference/web/async_chat_stream.html
      index cf5db2979..8e9d0ef91 100644
      --- a/docs/reference/web/async_chat_stream.html
      +++ b/docs/reference/web/async_chat_stream.html
      @@ -48,7 +48,7 @@ 

      Classes

      class AsyncChatStream -(client: AsyncWebClient,
      *,
      channel: str,
      logger: logging.Logger,
      thread_ts: str,
      buffer_size: int,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs)
      +(client: AsyncWebClient,
      *,
      channel: str,
      logger: logging.Logger,
      thread_ts: str,
      buffer_size: int,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs)
      @@ -58,8 +58,7 @@

      Classes

      class AsyncChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream,
      -    and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -72,37 +71,35 @@ 

      Classes

      buffer_size: int, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ): """Initialize a new ChatStream instance. + The __init__ method creates a unique ChatStream instance that keeps track of one chat stream. + Args: - client: The WebClient instance to use for API calls - channel: Channel ID to stream to - thread_ts: Thread timestamp to stream to - recipient_team_id: Team ID of the recipient - recipient_user_id: User ID of the recipient - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - buffer_size: Size of the internal buffer before automatically flushing (default: 256) + client: The WebClient instance to use for API calls. + channel: An encoded ID that represents a channel, private group, or DM. + logger: A logging channel for outputs. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client self._logger = logger + self._token: Optional[str] = kwargs.pop("token", None) self._stream_args = { "channel": channel, "thread_ts": thread_ts, "recipient_team_id": recipient_team_id, "recipient_user_id": recipient_user_id, - "unfurl_links": unfurl_links, - "unfurl_media": unfurl_media, **kwargs, } self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None - self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size async def append( @@ -111,17 +108,32 @@

      Classes

      markdown_text: str, **kwargs, ) -> Optional[AsyncSlackResponse]: - """Append markdown text to the stream. + """Append to the stream. + + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. Args: - markdown_text: The markdown text to append - **kwargs: Additional arguments passed to the underlying API calls + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - AsyncSlackResponse if the buffer was flushed, None if buffering + AsyncSlackResponse if the buffer was flushed, None if buffering. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") @@ -152,16 +164,29 @@

      Classes

      """Stop the stream and finalize the message. Args: - markdown_text: Additional markdown text to append before stopping - blocks: Message blocks to add to the final message - metadata: Message metadata to add to the final message - **kwargs: Additional arguments passed to the underlying API calls + blocks: A list of blocks that will be rendered at the bottom of the finalized message. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - AsyncSlackResponse from the chat.stopStream API call + AsyncSlackResponse from the chat.stopStream API call. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") @@ -209,32 +234,31 @@

      Classes

      **kwargs, markdown_text=self._buffer, ) - self._buffer = "" return response

      A helper class for streaming markdown text into a conversation using the chat streaming APIs.

      -

      This class provides a convenient interface for the chat.startStream, chat.appendStream, -and chat.stopStream API methods, with automatic buffering and state management.

      +

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.

      Initialize a new ChatStream instance.

      +

      The init method creates a unique ChatStream instance that keeps track of one chat stream.

      Args

      client
      -
      The WebClient instance to use for API calls
      +
      The WebClient instance to use for API calls.
      channel
      -
      Channel ID to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      +
      logger
      +
      A logging channel for outputs.
      thread_ts
      -
      Thread timestamp to stream to
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      **kwargs
      +
      Additional arguments passed to the underlying API calls.

      Methods

      @@ -252,17 +276,32 @@

      Methods

      markdown_text: str, **kwargs, ) -> Optional[AsyncSlackResponse]: - """Append markdown text to the stream. + """Append to the stream. + + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. Args: - markdown_text: The markdown text to append - **kwargs: Additional arguments passed to the underlying API calls + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - AsyncSlackResponse if the buffer was flushed, None if buffering + AsyncSlackResponse if the buffer was flushed, None if buffering. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") @@ -282,21 +321,33 @@

      Methods

      self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}") return None
      -

      Append markdown text to the stream.

      +

      Append to the stream.

      +

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.

      Args

      markdown_text
      -
      The markdown text to append
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      AsyncSlackResponse if the buffer was flushed, None if buffering

      +

      AsyncSlackResponse if the buffer was flushed, None if buffering.

      Raises

      SlackRequestError
      -
      If the stream is already completed
      -
      +
      If the stream is already completed.
      + +

      Example

      +
      streamer = client.chat_stream(
      +    channel="C0123456789",
      +    thread_ts="1700000001.123456",
      +    recipient_team_id="T0123456789",
      +    recipient_user_id="U0123456789",
      +)
      +streamer.append(markdown_text="**hello wo")
      +streamer.append(markdown_text="rld!**")
      +streamer.stop()
      +
      async def stop(self,
      *,
      markdown_text: str | None = None,
      blocks: str | Sequence[Dict | Block] | None = None,
      metadata: Dict | Metadata | None = None,
      **kwargs) ‑> AsyncSlackResponse
      @@ -317,16 +368,29 @@

      Raises

      """Stop the stream and finalize the message. Args: - markdown_text: Additional markdown text to append before stopping - blocks: Message blocks to add to the final message - metadata: Message metadata to add to the final message - **kwargs: Additional arguments passed to the underlying API calls + blocks: A list of blocks that will be rendered at the bottom of the finalized message. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - AsyncSlackResponse from the chat.stopStream API call + AsyncSlackResponse from the chat.stopStream API call. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") @@ -358,22 +422,33 @@

      Raises

      Stop the stream and finalize the message.

      Args

      -
      markdown_text
      -
      Additional markdown text to append before stopping
      blocks
      -
      Message blocks to add to the final message
      +
      A list of blocks that will be rendered at the bottom of the finalized message.
      +
      markdown_text
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      metadata
      -
      Message metadata to add to the final message
      +
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      AsyncSlackResponse from the chat.stopStream API call

      +

      AsyncSlackResponse from the chat.stopStream API call.

      Raises

      SlackRequestError
      -
      If the stream is already completed
      -
      +
      If the stream is already completed.
      + +

      Example

      +
      streamer = client.chat_stream(
      +    channel="C0123456789",
      +    thread_ts="1700000001.123456",
      +    recipient_team_id="T0123456789",
      +    recipient_user_id="U0123456789",
      +)
      +streamer.append(markdown_text="**hello wo")
      +streamer.append(markdown_text="rld!**")
      +streamer.stop()
      +
      diff --git a/docs/reference/web/async_client.html b/docs/reference/web/async_client.html index 66cf63ad4..24943a71f 100644 --- a/docs/reference/web/async_client.html +++ b/docs/reference/web/async_client.html @@ -2934,29 +2934,28 @@

      Classes

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> AsyncChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -2978,8 +2977,6 @@

      Classes

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, ) @@ -10301,7 +10298,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -async def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> AsyncChatStream
      +async def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs) ‑> AsyncChatStream
      @@ -10316,29 +10313,28 @@

      Methods

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> AsyncChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -10360,38 +10356,35 @@

      Methods

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, )

      Stream markdown text into a conversation.

      -

      This method provides an easy way to stream markdown text using the following endpoints: -- chat.startStream: Starts a new streaming conversation -- chat.appendStream: Appends text to an existing streaming conversation -- chat.stopStream: Stops a streaming conversation

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      The following methods are used:

      +
        +
      • chat.startStream: Starts a new streaming conversation. Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +

      Args

      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      channel
      -
      Channel to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Thread timestamp to stream to (required)
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient (for Slack Connect)
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient (for Slack Connect)
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      ChatStreamer instance for managing the stream

      +

      ChatStream instance for managing the stream

      Example

      streamer = await client.chat_stream(
           channel="C0123456789",
      diff --git a/docs/reference/web/chat_stream.html b/docs/reference/web/chat_stream.html
      index 434a5794b..2f4dea425 100644
      --- a/docs/reference/web/chat_stream.html
      +++ b/docs/reference/web/chat_stream.html
      @@ -48,7 +48,7 @@ 

      Classes

      class ChatStream -(client: WebClient,
      *,
      channel: str,
      logger: logging.Logger,
      thread_ts: str,
      buffer_size: int,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs)
      +(client: WebClient,
      *,
      channel: str,
      logger: logging.Logger,
      thread_ts: str,
      buffer_size: int,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs)
      @@ -58,8 +58,7 @@

      Classes

      class ChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream,
      -    and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -72,37 +71,35 @@ 

      Classes

      buffer_size: int, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ): """Initialize a new ChatStream instance. + The __init__ method creates a unique ChatStream instance that keeps track of one chat stream. + Args: - client: The WebClient instance to use for API calls - channel: Channel ID to stream to - thread_ts: Thread timestamp to stream to - recipient_team_id: Team ID of the recipient - recipient_user_id: User ID of the recipient - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - buffer_size: Size of the internal buffer before automatically flushing (default: 256) + client: The WebClient instance to use for API calls. + channel: An encoded ID that represents a channel, private group, or DM. + logger: A logging channel for outputs. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client self._logger = logger + self._token: Optional[str] = kwargs.pop("token", None) self._stream_args = { "channel": channel, "thread_ts": thread_ts, "recipient_team_id": recipient_team_id, "recipient_user_id": recipient_user_id, - "unfurl_links": unfurl_links, - "unfurl_media": unfurl_media, **kwargs, } self._buffer = "" self._state = "starting" self._stream_ts: Optional[str] = None - self._token: Optional[str] = kwargs.get("token") self._buffer_size = buffer_size def append( @@ -111,17 +108,32 @@

      Classes

      markdown_text: str, **kwargs, ) -> Optional[SlackResponse]: - """Append markdown text to the stream. + """Append to the stream. + + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. Args: - markdown_text: The markdown text to append - **kwargs: Additional arguments passed to the underlying API calls + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - SlackResponse if the buffer was flushed, None if buffering + SlackResponse if the buffer was flushed, None if buffering. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") @@ -152,16 +164,29 @@

      Classes

      """Stop the stream and finalize the message. Args: - markdown_text: Additional markdown text to append before stopping - blocks: Message blocks to add to the final message - metadata: Message metadata to add to the final message - **kwargs: Additional arguments passed to the underlying API calls + blocks: A list of blocks that will be rendered at the bottom of the finalized message. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - SlackResponse from the chat.stopStream API call + SlackResponse from the chat.stopStream API call. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") @@ -209,32 +234,31 @@

      Classes

      **kwargs, markdown_text=self._buffer, ) - self._buffer = "" return response

      A helper class for streaming markdown text into a conversation using the chat streaming APIs.

      -

      This class provides a convenient interface for the chat.startStream, chat.appendStream, -and chat.stopStream API methods, with automatic buffering and state management.

      +

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.

      Initialize a new ChatStream instance.

      +

      The init method creates a unique ChatStream instance that keeps track of one chat stream.

      Args

      client
      -
      The WebClient instance to use for API calls
      +
      The WebClient instance to use for API calls.
      channel
      -
      Channel ID to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      +
      logger
      +
      A logging channel for outputs.
      thread_ts
      -
      Thread timestamp to stream to
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      **kwargs
      +
      Additional arguments passed to the underlying API calls.

      Methods

      @@ -252,17 +276,32 @@

      Methods

      markdown_text: str, **kwargs, ) -> Optional[SlackResponse]: - """Append markdown text to the stream. + """Append to the stream. + + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. Args: - markdown_text: The markdown text to append - **kwargs: Additional arguments passed to the underlying API calls + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - SlackResponse if the buffer was flushed, None if buffering + SlackResponse if the buffer was flushed, None if buffering. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") @@ -282,21 +321,33 @@

      Methods

      self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}") return None
      -

      Append markdown text to the stream.

      +

      Append to the stream.

      +

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.

      Args

      markdown_text
      -
      The markdown text to append
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      SlackResponse if the buffer was flushed, None if buffering

      +

      SlackResponse if the buffer was flushed, None if buffering.

      Raises

      SlackRequestError
      -
      If the stream is already completed
      -
      +
      If the stream is already completed.
      + +

      Example

      +
      streamer = client.chat_stream(
      +    channel="C0123456789",
      +    thread_ts="1700000001.123456",
      +    recipient_team_id="T0123456789",
      +    recipient_user_id="U0123456789",
      +)
      +streamer.append(markdown_text="**hello wo")
      +streamer.append(markdown_text="rld!**")
      +streamer.stop()
      +
      def stop(self,
      *,
      markdown_text: str | None = None,
      blocks: str | Sequence[Dict | Block] | None = None,
      metadata: Dict | Metadata | None = None,
      **kwargs) ‑> SlackResponse
      @@ -317,16 +368,29 @@

      Raises

      """Stop the stream and finalize the message. Args: - markdown_text: Additional markdown text to append before stopping - blocks: Message blocks to add to the final message - metadata: Message metadata to add to the final message - **kwargs: Additional arguments passed to the underlying API calls + blocks: A list of blocks that will be rendered at the bottom of the finalized message. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - SlackResponse from the chat.stopStream API call + SlackResponse from the chat.stopStream API call. Raises: - SlackRequestError: If the stream is already completed + SlackRequestError: If the stream is already completed. + + Example: + ```python + streamer = client.chat_stream( + channel="C0123456789", + thread_ts="1700000001.123456", + recipient_team_id="T0123456789", + recipient_user_id="U0123456789", + ) + streamer.append(markdown_text="**hello wo") + streamer.append(markdown_text="rld!**") + streamer.stop() + ``` """ if self._state == "completed": raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") @@ -358,22 +422,33 @@

      Raises

      Stop the stream and finalize the message.

      Args

      -
      markdown_text
      -
      Additional markdown text to append before stopping
      blocks
      -
      Message blocks to add to the final message
      +
      A list of blocks that will be rendered at the bottom of the finalized message.
      +
      markdown_text
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      metadata
      -
      Message metadata to add to the final message
      +
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      SlackResponse from the chat.stopStream API call

      +

      SlackResponse from the chat.stopStream API call.

      Raises

      SlackRequestError
      -
      If the stream is already completed
      -
      +
      If the stream is already completed.
      + +

      Example

      +
      streamer = client.chat_stream(
      +    channel="C0123456789",
      +    thread_ts="1700000001.123456",
      +    recipient_team_id="T0123456789",
      +    recipient_user_id="U0123456789",
      +)
      +streamer.append(markdown_text="**hello wo")
      +streamer.append(markdown_text="rld!**")
      +streamer.stop()
      +
      diff --git a/docs/reference/web/client.html b/docs/reference/web/client.html index b28f6e956..886ada4ad 100644 --- a/docs/reference/web/client.html +++ b/docs/reference/web/client.html @@ -2934,29 +2934,28 @@

      Classes

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -2978,8 +2977,6 @@

      Classes

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, ) @@ -10301,7 +10298,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs) ‑> ChatStream
      @@ -10316,29 +10313,28 @@

      Methods

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -10360,38 +10356,35 @@

      Methods

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, )

      Stream markdown text into a conversation.

      -

      This method provides an easy way to stream markdown text using the following endpoints: -- chat.startStream: Starts a new streaming conversation -- chat.appendStream: Appends text to an existing streaming conversation -- chat.stopStream: Stops a streaming conversation

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      The following methods are used:

      +
        +
      • chat.startStream: Starts a new streaming conversation. Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +

      Args

      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      channel
      -
      Channel to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Thread timestamp to stream to (required)
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient (for Slack Connect)
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient (for Slack Connect)
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      ChatStreamer instance for managing the stream

      +

      ChatStream instance for managing the stream

      Example

      streamer = client.chat_stream(
           channel="C0123456789",
      diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html
      index 6fccde48a..3a8f81cc6 100644
      --- a/docs/reference/web/index.html
      +++ b/docs/reference/web/index.html
      @@ -3303,29 +3303,28 @@ 

      Raises

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -3347,8 +3346,6 @@

      Raises

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, ) @@ -10670,7 +10667,7 @@

      Methods

      https://api.slack.com/methods/chat.stopStream

      -def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      unfurl_links: bool | None = None,
      unfurl_media: bool | None = None,
      **kwargs) ‑> ChatStream
      +def chat_stream(self,
      *,
      buffer_size: int = 256,
      channel: str,
      thread_ts: str,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      **kwargs) ‑> ChatStream
      @@ -10685,29 +10682,28 @@

      Methods

      thread_ts: str, recipient_team_id: Optional[str] = None, recipient_user_id: Optional[str] = None, - unfurl_links: Optional[bool] = None, - unfurl_media: Optional[bool] = None, **kwargs, ) -> ChatStream: """Stream markdown text into a conversation. - This method provides an easy way to stream markdown text using the following endpoints: - - chat.startStream: Starts a new streaming conversation - - chat.appendStream: Appends text to an existing streaming conversation - - chat.stopStream: Stops a streaming conversation + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + + The following methods are used: + + - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: Size of the internal buffer before automatically flushing (default: 256) - channel: Channel to stream to - thread_ts: Thread timestamp to stream to (required) - recipient_team_id: Team ID of the recipient (for Slack Connect) - recipient_user_id: User ID of the recipient (for Slack Connect) - unfurl_links: Whether to unfurl links - unfurl_media: Whether to unfurl media - **kwargs: Additional arguments passed to the underlying API calls + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + channel: An encoded ID that represents a channel, private group, or DM. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. + **kwargs: Additional arguments passed to the underlying API calls. Returns: - ChatStreamer instance for managing the stream + ChatStream instance for managing the stream Example: ```python @@ -10729,38 +10725,35 @@

      Methods

      thread_ts=thread_ts, recipient_team_id=recipient_team_id, recipient_user_id=recipient_user_id, - unfurl_links=unfurl_links, - unfurl_media=unfurl_media, buffer_size=buffer_size, **kwargs, )

      Stream markdown text into a conversation.

      -

      This method provides an easy way to stream markdown text using the following endpoints: -- chat.startStream: Starts a new streaming conversation -- chat.appendStream: Appends text to an existing streaming conversation -- chat.stopStream: Stops a streaming conversation

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      The following methods are used:

      +
        +
      • chat.startStream: Starts a new streaming conversation. Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +

      Args

      buffer_size
      -
      Size of the internal buffer before automatically flushing (default: 256)
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      channel
      -
      Channel to stream to
      +
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Thread timestamp to stream to (required)
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      recipient_team_id
      -
      Team ID of the recipient (for Slack Connect)
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      recipient_user_id
      -
      User ID of the recipient (for Slack Connect)
      -
      unfurl_links
      -
      Whether to unfurl links
      -
      unfurl_media
      -
      Whether to unfurl media
      +
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      -
      Additional arguments passed to the underlying API calls
      +
      Additional arguments passed to the underlying API calls.

      Returns

      -

      ChatStreamer instance for managing the stream

      +

      ChatStream instance for managing the stream

      Example

      streamer = client.chat_stream(
           channel="C0123456789",
      diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py
      index ccf7b1969..a94c8d00b 100644
      --- a/slack_sdk/web/async_chat_stream.py
      +++ b/slack_sdk/web/async_chat_stream.py
      @@ -24,8 +24,7 @@
       class AsyncChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream,
      -    and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -38,37 +37,35 @@ def __init__(
               buffer_size: int,
               recipient_team_id: Optional[str] = None,
               recipient_user_id: Optional[str] = None,
      -        unfurl_links: Optional[bool] = None,
      -        unfurl_media: Optional[bool] = None,
               **kwargs,
           ):
               """Initialize a new ChatStream instance.
       
      +        The __init__ method creates a unique ChatStream instance that keeps track of one chat stream.
      +
               Args:
      -            client: The WebClient instance to use for API calls
      -            channel: Channel ID to stream to
      -            thread_ts: Thread timestamp to stream to
      -            recipient_team_id: Team ID of the recipient
      -            recipient_user_id: User ID of the recipient
      -            unfurl_links: Whether to unfurl links
      -            unfurl_media: Whether to unfurl media
      -            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      +            client: The WebClient instance to use for API calls.
      +            channel: An encoded ID that represents a channel, private group, or DM.
      +            logger: A logging channel for outputs.
      +            thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +            recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +            recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      +            buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +            **kwargs: Additional arguments passed to the underlying API calls.
               """
               self._client = client
               self._logger = logger
      +        self._token: Optional[str] = kwargs.pop("token", None)
               self._stream_args = {
                   "channel": channel,
                   "thread_ts": thread_ts,
                   "recipient_team_id": recipient_team_id,
                   "recipient_user_id": recipient_user_id,
      -            "unfurl_links": unfurl_links,
      -            "unfurl_media": unfurl_media,
                   **kwargs,
               }
               self._buffer = ""
               self._state = "starting"
               self._stream_ts: Optional[str] = None
      -        self._token: Optional[str] = kwargs.get("token")
               self._buffer_size = buffer_size
       
           async def append(
      @@ -77,17 +74,32 @@ async def append(
               markdown_text: str,
               **kwargs,
           ) -> Optional[AsyncSlackResponse]:
      -        """Append markdown text to the stream.
      +        """Append to the stream.
      +
      +        The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.
       
               Args:
      -            markdown_text: The markdown text to append
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            AsyncSlackResponse if the buffer was flushed, None if buffering
      +            AsyncSlackResponse if the buffer was flushed, None if buffering.
       
               Raises:
      -            SlackRequestError: If the stream is already completed
      +            SlackRequestError: If the stream is already completed.
      +
      +        Example:
      +            ```python
      +            streamer = client.chat_stream(
      +                channel="C0123456789",
      +                thread_ts="1700000001.123456",
      +                recipient_team_id="T0123456789",
      +                recipient_user_id="U0123456789",
      +            )
      +            streamer.append(markdown_text="**hello wo")
      +            streamer.append(markdown_text="rld!**")
      +            streamer.stop()
      +            ```
               """
               if self._state == "completed":
                   raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
      @@ -118,16 +130,29 @@ async def stop(
               """Stop the stream and finalize the message.
       
               Args:
      -            markdown_text: Additional markdown text to append before stopping
      -            blocks: Message blocks to add to the final message
      -            metadata: Message metadata to add to the final message
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            blocks: A list of blocks that will be rendered at the bottom of the finalized message.
      +            markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +            metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            AsyncSlackResponse from the chat.stopStream API call
      +            AsyncSlackResponse from the chat.stopStream API call.
       
               Raises:
      -            SlackRequestError: If the stream is already completed
      +            SlackRequestError: If the stream is already completed.
      +
      +        Example:
      +            ```python
      +            streamer = client.chat_stream(
      +                channel="C0123456789",
      +                thread_ts="1700000001.123456",
      +                recipient_team_id="T0123456789",
      +                recipient_user_id="U0123456789",
      +            )
      +            streamer.append(markdown_text="**hello wo")
      +            streamer.append(markdown_text="rld!**")
      +            streamer.stop()
      +            ```
               """
               if self._state == "completed":
                   raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
      @@ -175,6 +200,5 @@ async def _flush_buffer(self, **kwargs) -> AsyncSlackResponse:
                       **kwargs,
                       markdown_text=self._buffer,
                   )
      -
               self._buffer = ""
               return response
      diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py
      index bb776efb7..74d385129 100644
      --- a/slack_sdk/web/async_client.py
      +++ b/slack_sdk/web/async_client.py
      @@ -2913,29 +2913,28 @@ async def chat_stream(
               thread_ts: str,
               recipient_team_id: Optional[str] = None,
               recipient_user_id: Optional[str] = None,
      -        unfurl_links: Optional[bool] = None,
      -        unfurl_media: Optional[bool] = None,
               **kwargs,
           ) -> AsyncChatStream:
               """Stream markdown text into a conversation.
       
      -        This method provides an easy way to stream markdown text using the following endpoints:
      -        - chat.startStream: Starts a new streaming conversation
      -        - chat.appendStream: Appends text to an existing streaming conversation
      -        - chat.stopStream: Stops a streaming conversation
      +        This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.
      +
      +        The following methods are used:
      +
      +        - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream).
      +        - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream).
      +        - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream).
       
               Args:
      -            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      -            channel: Channel to stream to
      -            thread_ts: Thread timestamp to stream to (required)
      -            recipient_team_id: Team ID of the recipient (for Slack Connect)
      -            recipient_user_id: User ID of the recipient (for Slack Connect)
      -            unfurl_links: Whether to unfurl links
      -            unfurl_media: Whether to unfurl media
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +            channel: An encoded ID that represents a channel, private group, or DM.
      +            thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +            recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +            recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            ChatStreamer instance for managing the stream
      +            ChatStream instance for managing the stream
       
               Example:
                   ```python
      @@ -2957,8 +2956,6 @@ async def chat_stream(
                   thread_ts=thread_ts,
                   recipient_team_id=recipient_team_id,
                   recipient_user_id=recipient_user_id,
      -            unfurl_links=unfurl_links,
      -            unfurl_media=unfurl_media,
                   buffer_size=buffer_size,
                   **kwargs,
               )
      diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py
      index 6923fba98..47d77b450 100644
      --- a/slack_sdk/web/chat_stream.py
      +++ b/slack_sdk/web/chat_stream.py
      @@ -14,8 +14,7 @@
       class ChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream,
      -    and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -28,37 +27,35 @@ def __init__(
               buffer_size: int,
               recipient_team_id: Optional[str] = None,
               recipient_user_id: Optional[str] = None,
      -        unfurl_links: Optional[bool] = None,
      -        unfurl_media: Optional[bool] = None,
               **kwargs,
           ):
               """Initialize a new ChatStream instance.
       
      +        The __init__ method creates a unique ChatStream instance that keeps track of one chat stream.
      +
               Args:
      -            client: The WebClient instance to use for API calls
      -            channel: Channel ID to stream to
      -            thread_ts: Thread timestamp to stream to
      -            recipient_team_id: Team ID of the recipient
      -            recipient_user_id: User ID of the recipient
      -            unfurl_links: Whether to unfurl links
      -            unfurl_media: Whether to unfurl media
      -            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      +            client: The WebClient instance to use for API calls.
      +            channel: An encoded ID that represents a channel, private group, or DM.
      +            logger: A logging channel for outputs.
      +            thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +            recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +            recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      +            buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +            **kwargs: Additional arguments passed to the underlying API calls.
               """
               self._client = client
               self._logger = logger
      +        self._token: Optional[str] = kwargs.pop("token", None)
               self._stream_args = {
                   "channel": channel,
                   "thread_ts": thread_ts,
                   "recipient_team_id": recipient_team_id,
                   "recipient_user_id": recipient_user_id,
      -            "unfurl_links": unfurl_links,
      -            "unfurl_media": unfurl_media,
                   **kwargs,
               }
               self._buffer = ""
               self._state = "starting"
               self._stream_ts: Optional[str] = None
      -        self._token: Optional[str] = kwargs.get("token")
               self._buffer_size = buffer_size
       
           def append(
      @@ -67,17 +64,32 @@ def append(
               markdown_text: str,
               **kwargs,
           ) -> Optional[SlackResponse]:
      -        """Append markdown text to the stream.
      +        """Append to the stream.
      +
      +        The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.
       
               Args:
      -            markdown_text: The markdown text to append
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            SlackResponse if the buffer was flushed, None if buffering
      +            SlackResponse if the buffer was flushed, None if buffering.
       
               Raises:
      -            SlackRequestError: If the stream is already completed
      +            SlackRequestError: If the stream is already completed.
      +
      +        Example:
      +            ```python
      +            streamer = client.chat_stream(
      +                channel="C0123456789",
      +                thread_ts="1700000001.123456",
      +                recipient_team_id="T0123456789",
      +                recipient_user_id="U0123456789",
      +            )
      +            streamer.append(markdown_text="**hello wo")
      +            streamer.append(markdown_text="rld!**")
      +            streamer.stop()
      +            ```
               """
               if self._state == "completed":
                   raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}")
      @@ -108,16 +120,29 @@ def stop(
               """Stop the stream and finalize the message.
       
               Args:
      -            markdown_text: Additional markdown text to append before stopping
      -            blocks: Message blocks to add to the final message
      -            metadata: Message metadata to add to the final message
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            blocks: A list of blocks that will be rendered at the bottom of the finalized message.
      +            markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +            metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            SlackResponse from the chat.stopStream API call
      +            SlackResponse from the chat.stopStream API call.
       
               Raises:
      -            SlackRequestError: If the stream is already completed
      +            SlackRequestError: If the stream is already completed.
      +
      +        Example:
      +            ```python
      +            streamer = client.chat_stream(
      +                channel="C0123456789",
      +                thread_ts="1700000001.123456",
      +                recipient_team_id="T0123456789",
      +                recipient_user_id="U0123456789",
      +            )
      +            streamer.append(markdown_text="**hello wo")
      +            streamer.append(markdown_text="rld!**")
      +            streamer.stop()
      +            ```
               """
               if self._state == "completed":
                   raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}")
      @@ -165,6 +190,5 @@ def _flush_buffer(self, **kwargs) -> SlackResponse:
                       **kwargs,
                       markdown_text=self._buffer,
                   )
      -
               self._buffer = ""
               return response
      diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py
      index a1afb6f8c..3caabe99b 100644
      --- a/slack_sdk/web/client.py
      +++ b/slack_sdk/web/client.py
      @@ -2903,29 +2903,28 @@ def chat_stream(
               thread_ts: str,
               recipient_team_id: Optional[str] = None,
               recipient_user_id: Optional[str] = None,
      -        unfurl_links: Optional[bool] = None,
      -        unfurl_media: Optional[bool] = None,
               **kwargs,
           ) -> ChatStream:
               """Stream markdown text into a conversation.
       
      -        This method provides an easy way to stream markdown text using the following endpoints:
      -        - chat.startStream: Starts a new streaming conversation
      -        - chat.appendStream: Appends text to an existing streaming conversation
      -        - chat.stopStream: Stops a streaming conversation
      +        This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.
      +
      +        The following methods are used:
      +
      +        - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream).
      +        - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream).
      +        - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream).
       
               Args:
      -            buffer_size: Size of the internal buffer before automatically flushing (default: 256)
      -            channel: Channel to stream to
      -            thread_ts: Thread timestamp to stream to (required)
      -            recipient_team_id: Team ID of the recipient (for Slack Connect)
      -            recipient_user_id: User ID of the recipient (for Slack Connect)
      -            unfurl_links: Whether to unfurl links
      -            unfurl_media: Whether to unfurl media
      -            **kwargs: Additional arguments passed to the underlying API calls
      +            buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +            channel: An encoded ID that represents a channel, private group, or DM.
      +            thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +            recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +            recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      +            **kwargs: Additional arguments passed to the underlying API calls.
       
               Returns:
      -            ChatStreamer instance for managing the stream
      +            ChatStream instance for managing the stream
       
               Example:
                   ```python
      @@ -2947,8 +2946,6 @@ def chat_stream(
                   thread_ts=thread_ts,
                   recipient_team_id=recipient_team_id,
                   recipient_user_id=recipient_user_id,
      -            unfurl_links=unfurl_links,
      -            unfurl_media=unfurl_media,
                   buffer_size=buffer_size,
                   **kwargs,
               )
      diff --git a/tests/slack_sdk/web/test_chat_stream.py b/tests/slack_sdk/web/test_chat_stream.py
      index 5b0ecee87..d9571f44f 100644
      --- a/tests/slack_sdk/web/test_chat_stream.py
      +++ b/tests/slack_sdk/web/test_chat_stream.py
      @@ -4,6 +4,7 @@
       from urllib.parse import parse_qs, urlparse
       
       from slack_sdk import WebClient
      +from slack_sdk.errors import SlackRequestError
       from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server
       from tests.slack_sdk.web.mock_web_api_handler import MockHandler
       
      @@ -116,10 +117,10 @@ def test_streams_a_long_message(self):
                   thread_ts="123.000",
               )
               streamer.append(markdown_text="**this messag")
      -        streamer.append(markdown_text="e is")
      +        streamer.append(markdown_text="e is", token="xoxb-chat_stream_test_token1")
               streamer.append(markdown_text=" bold!")
               streamer.append(markdown_text="*")
      -        streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token")
      +        streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token2")
       
               self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1)
               self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1)
      @@ -136,10 +137,32 @@ def test_streams_a_long_message(self):
                   append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {})
                   self.assertEqual(append_request.get("channel"), "C0123456789")
                   self.assertEqual(append_request.get("markdown_text"), "e is bold!")
      +            self.assertEqual(append_request.get("token"), "xoxb-chat_stream_test_token1")
                   self.assertEqual(append_request.get("ts"), "123.123")
       
                   stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {})
                   self.assertEqual(stop_request.get("channel"), "C0123456789")
                   self.assertEqual(stop_request.get("markdown_text"), "**")
      -            self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token")
      +            self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token2")
                   self.assertEqual(stop_request.get("ts"), "123.123")
      +
      +    def test_streams_errors_when_appending_to_an_unstarted_stream(self):
      +        streamer = self.client.chat_stream(
      +            channel="C0123456789",
      +            thread_ts="123.000",
      +            token="xoxb-chat_stream_test_missing_ts",
      +        )
      +        with self.assertRaisesRegex(SlackRequestError, r"^Failed to stop stream: stream not started$"):
      +            streamer.stop()
      +
      +    def test_streams_errors_when_appending_to_a_completed_stream(self):
      +        streamer = self.client.chat_stream(
      +            channel="C0123456789",
      +            thread_ts="123.000",
      +        )
      +        streamer.append(markdown_text="nice!")
      +        streamer.stop()
      +        with self.assertRaisesRegex(SlackRequestError, r"^Cannot append to stream: stream state is completed$"):
      +            streamer.append(markdown_text="more...")
      +        with self.assertRaisesRegex(SlackRequestError, r"^Cannot stop stream: stream state is completed$"):
      +            streamer.stop()
      diff --git a/tests/slack_sdk_async/web/test_async_chat_stream.py b/tests/slack_sdk_async/web/test_async_chat_stream.py
      index 01c564ded..48764c825 100644
      --- a/tests/slack_sdk_async/web/test_async_chat_stream.py
      +++ b/tests/slack_sdk_async/web/test_async_chat_stream.py
      @@ -3,6 +3,7 @@
       import unittest
       from urllib.parse import parse_qs, urlparse
       
      +from slack_sdk.errors import SlackRequestError
       from slack_sdk.web.async_client import AsyncWebClient
       from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server
       from tests.slack_sdk.web.mock_web_api_handler import MockHandler
      @@ -119,10 +120,10 @@ async def test_streams_a_long_message(self):
                   thread_ts="123.000",
               )
               await streamer.append(markdown_text="**this messag")
      -        await streamer.append(markdown_text="e is")
      +        await streamer.append(markdown_text="e is", token="xoxb-chat_stream_test_token1")
               await streamer.append(markdown_text=" bold!")
               await streamer.append(markdown_text="*")
      -        await streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token")
      +        await streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token2")
       
               self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1)
               self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1)
      @@ -139,10 +140,34 @@ async def test_streams_a_long_message(self):
                   append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {})
                   self.assertEqual(append_request.get("channel"), "C0123456789")
                   self.assertEqual(append_request.get("markdown_text"), "e is bold!")
      +            self.assertEqual(append_request.get("token"), "xoxb-chat_stream_test_token1")
                   self.assertEqual(append_request.get("ts"), "123.123")
       
                   stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {})
                   self.assertEqual(stop_request.get("channel"), "C0123456789")
                   self.assertEqual(stop_request.get("markdown_text"), "**")
      -            self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token")
      +            self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token2")
                   self.assertEqual(stop_request.get("ts"), "123.123")
      +
      +    @async_test
      +    async def test_streams_errors_when_appending_to_an_unstarted_stream(self):
      +        streamer = await self.client.chat_stream(
      +            channel="C0123456789",
      +            thread_ts="123.000",
      +            token="xoxb-chat_stream_test_missing_ts",
      +        )
      +        with self.assertRaisesRegex(SlackRequestError, r"^Failed to stop stream: stream not started$"):
      +            await streamer.stop()
      +
      +    @async_test
      +    async def test_streams_errors_when_appending_to_a_completed_stream(self):
      +        streamer = await self.client.chat_stream(
      +            channel="C0123456789",
      +            thread_ts="123.000",
      +        )
      +        await streamer.append(markdown_text="nice!")
      +        await streamer.stop()
      +        with self.assertRaisesRegex(SlackRequestError, r"^Cannot append to stream: stream state is completed$"):
      +            await streamer.append(markdown_text="more...")
      +        with self.assertRaisesRegex(SlackRequestError, r"^Cannot stop stream: stream state is completed$"):
      +            await streamer.stop()
      diff --git a/tests/slack_sdk_fixture/web_response_chat_stream_test_token.json b/tests/slack_sdk_fixture/web_response_chat_stream_test_missing_ts.json
      similarity index 100%
      rename from tests/slack_sdk_fixture/web_response_chat_stream_test_token.json
      rename to tests/slack_sdk_fixture/web_response_chat_stream_test_missing_ts.json
      diff --git a/tests/slack_sdk_fixture/web_response_chat_stream_test_token1.json b/tests/slack_sdk_fixture/web_response_chat_stream_test_token1.json
      new file mode 100644
      index 000000000..0287aedde
      --- /dev/null
      +++ b/tests/slack_sdk_fixture/web_response_chat_stream_test_token1.json
      @@ -0,0 +1,3 @@
      +{
      +  "ok": true
      +}
      diff --git a/tests/slack_sdk_fixture/web_response_chat_stream_test_token2.json b/tests/slack_sdk_fixture/web_response_chat_stream_test_token2.json
      new file mode 100644
      index 000000000..0287aedde
      --- /dev/null
      +++ b/tests/slack_sdk_fixture/web_response_chat_stream_test_token2.json
      @@ -0,0 +1,3 @@
      +{
      +  "ok": true
      +}
      
      From b7964ad45298062a3a0b11315933db165eb5f7ff Mon Sep 17 00:00:00 2001
      From: Eden Zimbelman 
      Date: Wed, 1 Oct 2025 16:26:51 -0700
      Subject: [PATCH 11/18] style: alphabetical methods
      
      ---
       scripts/codegen.py            |  2 +-
       slack_sdk/web/async_client.py | 52 +++++++++++++++++------------------
       slack_sdk/web/client.py       | 52 +++++++++++++++++------------------
       3 files changed, 53 insertions(+), 53 deletions(-)
      
      diff --git a/scripts/codegen.py b/scripts/codegen.py
      index b23088b5a..53b6d65e4 100644
      --- a/scripts/codegen.py
      +++ b/scripts/codegen.py
      @@ -120,7 +120,7 @@
           )
           legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source)
           legacy_source = re.sub(r"from slack_sdk.web.chat_stream import ChatStream", "", legacy_source)
      -    legacy_source = re.sub(r"(?s)def chat_stream.*?(?=def\s+chat_stopStream\()", "", legacy_source)
      +    legacy_source = re.sub(r"(?s)def chat_stream.*?(?=def)", "", legacy_source)
           with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output:
               output.write(legacy_source)
       
      diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py
      index 74d385129..54146d590 100644
      --- a/slack_sdk/web/async_client.py
      +++ b/slack_sdk/web/async_client.py
      @@ -2905,6 +2905,32 @@ async def chat_startStream(
               kwargs = _remove_none_values(kwargs)
               return await self.api_call("chat.startStream", json=kwargs)
       
      +    async def chat_stopStream(
      +        self,
      +        *,
      +        channel: str,
      +        ts: str,
      +        markdown_text: Optional[str] = None,
      +        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
      +        metadata: Optional[Union[Dict, Metadata]] = None,
      +        **kwargs,
      +    ) -> AsyncSlackResponse:
      +        """Stops a streaming conversation.
      +        https://api.slack.com/methods/chat.stopStream
      +        """
      +        kwargs.update(
      +            {
      +                "channel": channel,
      +                "ts": ts,
      +                "markdown_text": markdown_text,
      +                "blocks": blocks,
      +                "metadata": metadata,
      +            }
      +        )
      +        _parse_web_class_objects(kwargs)
      +        kwargs = _remove_none_values(kwargs)
      +        return await self.api_call("chat.stopStream", json=kwargs)
      +
           async def chat_stream(
               self,
               *,
      @@ -2960,32 +2986,6 @@ async def chat_stream(
                   **kwargs,
               )
       
      -    async def chat_stopStream(
      -        self,
      -        *,
      -        channel: str,
      -        ts: str,
      -        markdown_text: Optional[str] = None,
      -        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
      -        metadata: Optional[Union[Dict, Metadata]] = None,
      -        **kwargs,
      -    ) -> AsyncSlackResponse:
      -        """Stops a streaming conversation.
      -        https://api.slack.com/methods/chat.stopStream
      -        """
      -        kwargs.update(
      -            {
      -                "channel": channel,
      -                "ts": ts,
      -                "markdown_text": markdown_text,
      -                "blocks": blocks,
      -                "metadata": metadata,
      -            }
      -        )
      -        _parse_web_class_objects(kwargs)
      -        kwargs = _remove_none_values(kwargs)
      -        return await self.api_call("chat.stopStream", json=kwargs)
      -
           async def chat_unfurl(
               self,
               *,
      diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py
      index 3caabe99b..a1bb4397b 100644
      --- a/slack_sdk/web/client.py
      +++ b/slack_sdk/web/client.py
      @@ -2895,6 +2895,32 @@ def chat_startStream(
               kwargs = _remove_none_values(kwargs)
               return self.api_call("chat.startStream", json=kwargs)
       
      +    def chat_stopStream(
      +        self,
      +        *,
      +        channel: str,
      +        ts: str,
      +        markdown_text: Optional[str] = None,
      +        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
      +        metadata: Optional[Union[Dict, Metadata]] = None,
      +        **kwargs,
      +    ) -> SlackResponse:
      +        """Stops a streaming conversation.
      +        https://api.slack.com/methods/chat.stopStream
      +        """
      +        kwargs.update(
      +            {
      +                "channel": channel,
      +                "ts": ts,
      +                "markdown_text": markdown_text,
      +                "blocks": blocks,
      +                "metadata": metadata,
      +            }
      +        )
      +        _parse_web_class_objects(kwargs)
      +        kwargs = _remove_none_values(kwargs)
      +        return self.api_call("chat.stopStream", json=kwargs)
      +
           def chat_stream(
               self,
               *,
      @@ -2950,32 +2976,6 @@ def chat_stream(
                   **kwargs,
               )
       
      -    def chat_stopStream(
      -        self,
      -        *,
      -        channel: str,
      -        ts: str,
      -        markdown_text: Optional[str] = None,
      -        blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
      -        metadata: Optional[Union[Dict, Metadata]] = None,
      -        **kwargs,
      -    ) -> SlackResponse:
      -        """Stops a streaming conversation.
      -        https://api.slack.com/methods/chat.stopStream
      -        """
      -        kwargs.update(
      -            {
      -                "channel": channel,
      -                "ts": ts,
      -                "markdown_text": markdown_text,
      -                "blocks": blocks,
      -                "metadata": metadata,
      -            }
      -        )
      -        _parse_web_class_objects(kwargs)
      -        kwargs = _remove_none_values(kwargs)
      -        return self.api_call("chat.stopStream", json=kwargs)
      -
           def chat_unfurl(
               self,
               *,
      
      From 8a8ecb323582a0c23f94fbc92d60fabe7cc7d8ed Mon Sep 17 00:00:00 2001
      From: Eden Zimbelman 
      Date: Wed, 1 Oct 2025 16:32:21 -0700
      Subject: [PATCH 12/18] style: lint
      
      ---
       docs/reference/index.html                 | 118 +++++++++++++---------
       docs/reference/web/async_chat_stream.html |  62 ++++++++----
       docs/reference/web/async_client.html      | 118 +++++++++++++---------
       docs/reference/web/chat_stream.html       |  62 ++++++++----
       docs/reference/web/client.html            | 118 +++++++++++++---------
       docs/reference/web/index.html             | 118 +++++++++++++---------
       slack_sdk/web/async_chat_stream.py        |  25 +++--
       slack_sdk/web/async_client.py             |  22 ++--
       slack_sdk/web/chat_stream.py              |  25 +++--
       slack_sdk/web/client.py                   |  22 ++--
       10 files changed, 432 insertions(+), 258 deletions(-)
      
      diff --git a/docs/reference/index.html b/docs/reference/index.html
      index 76fdfb093..e7185c898 100644
      --- a/docs/reference/index.html
      +++ b/docs/reference/index.html
      @@ -3030,6 +3030,32 @@ 

      Classes

      kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stopStream( + self, + *, + channel: str, + ts: str, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> SlackResponse: + """Stops a streaming conversation. + https://api.slack.com/methods/chat.stopStream + """ + kwargs.update( + { + "channel": channel, + "ts": ts, + "markdown_text": markdown_text, + "blocks": blocks, + "metadata": metadata, + } + ) + _parse_web_class_objects(kwargs) + kwargs = _remove_none_values(kwargs) + return self.api_call("chat.stopStream", json=kwargs) + def chat_stream( self, *, @@ -3042,19 +3068,27 @@

      Classes

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -3085,32 +3119,6 @@

      Classes

      **kwargs, ) - def chat_stopStream( - self, - *, - channel: str, - ts: str, - markdown_text: Optional[str] = None, - blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, - metadata: Optional[Union[Dict, Metadata]] = None, - **kwargs, - ) -> SlackResponse: - """Stops a streaming conversation. - https://api.slack.com/methods/chat.stopStream - """ - kwargs.update( - { - "channel": channel, - "ts": ts, - "markdown_text": markdown_text, - "blocks": blocks, - "metadata": metadata, - } - ) - _parse_web_class_objects(kwargs) - kwargs = _remove_none_values(kwargs) - return self.api_call("chat.stopStream", json=kwargs) - def chat_unfurl( self, *, @@ -10421,19 +10429,27 @@

      Methods

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -10465,23 +10481,31 @@

      Methods

      )

      Stream markdown text into a conversation.

      -

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, +the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      The following methods are used:

        -
      • chat.startStream: Starts a new streaming conversation. Reference.
      • -
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • -
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +
      • chat.startStream: Starts a new streaming conversation. +Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. +Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. +Reference.

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      diff --git a/docs/reference/web/async_chat_stream.html b/docs/reference/web/async_chat_stream.html index 8e9d0ef91..25240ef76 100644 --- a/docs/reference/web/async_chat_stream.html +++ b/docs/reference/web/async_chat_stream.html @@ -58,7 +58,8 @@

      Classes

      class AsyncChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API
      +    methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -81,10 +82,14 @@ 

      Classes

      client: The WebClient instance to use for API calls. channel: An encoded ID that represents a channel, private group, or DM. logger: A logging channel for outputs. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -110,10 +115,12 @@

      Classes

      ) -> Optional[AsyncSlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -165,8 +172,10 @@

      Classes

      Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -238,7 +247,8 @@

      Classes

      return response

      A helper class for streaming markdown text into a conversation using the chat streaming APIs.

      -

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.

      +

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API +methods, with automatic buffering and state management.

      Initialize a new ChatStream instance.

      The init method creates a unique ChatStream instance that keeps track of one chat stream.

      Args

      @@ -250,13 +260,17 @@

      Args

      logger
      A logging channel for outputs.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      **kwargs
      Additional arguments passed to the underlying API calls.
      @@ -278,10 +292,12 @@

      Methods

      ) -> Optional[AsyncSlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -322,11 +338,13 @@

      Methods

      return None

      Append to the stream.

      -

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.

      +

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream +is stopped this method cannot be called.

      Args

      markdown_text
      -
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is +what will be appended to the message received so far.
      **kwargs
      Additional arguments passed to the underlying API calls.
      @@ -369,8 +387,10 @@

      Example

      Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -425,9 +445,11 @@

      Args

      blocks
      A list of blocks that will be rendered at the bottom of the finalized message.
      markdown_text
      -
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is +what will be appended to the message received so far.
      metadata
      -
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      +
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you +post to Slack is accessible to any app or user who is a member of that workspace.
      **kwargs
      Additional arguments passed to the underlying API calls.
      diff --git a/docs/reference/web/async_client.html b/docs/reference/web/async_client.html index 24943a71f..efec8c06e 100644 --- a/docs/reference/web/async_client.html +++ b/docs/reference/web/async_client.html @@ -2926,6 +2926,32 @@

      Classes

      kwargs = _remove_none_values(kwargs) return await self.api_call("chat.startStream", json=kwargs) + async def chat_stopStream( + self, + *, + channel: str, + ts: str, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> AsyncSlackResponse: + """Stops a streaming conversation. + https://api.slack.com/methods/chat.stopStream + """ + kwargs.update( + { + "channel": channel, + "ts": ts, + "markdown_text": markdown_text, + "blocks": blocks, + "metadata": metadata, + } + ) + _parse_web_class_objects(kwargs) + kwargs = _remove_none_values(kwargs) + return await self.api_call("chat.stopStream", json=kwargs) + async def chat_stream( self, *, @@ -2938,19 +2964,27 @@

      Classes

      ) -> AsyncChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -2981,32 +3015,6 @@

      Classes

      **kwargs, ) - async def chat_stopStream( - self, - *, - channel: str, - ts: str, - markdown_text: Optional[str] = None, - blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, - metadata: Optional[Union[Dict, Metadata]] = None, - **kwargs, - ) -> AsyncSlackResponse: - """Stops a streaming conversation. - https://api.slack.com/methods/chat.stopStream - """ - kwargs.update( - { - "channel": channel, - "ts": ts, - "markdown_text": markdown_text, - "blocks": blocks, - "metadata": metadata, - } - ) - _parse_web_class_objects(kwargs) - kwargs = _remove_none_values(kwargs) - return await self.api_call("chat.stopStream", json=kwargs) - async def chat_unfurl( self, *, @@ -10317,19 +10325,27 @@

      Methods

      ) -> AsyncChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -10361,23 +10377,31 @@

      Methods

      )

      Stream markdown text into a conversation.

      -

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, +the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      The following methods are used:

        -
      • chat.startStream: Starts a new streaming conversation. Reference.
      • -
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • -
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +
      • chat.startStream: Starts a new streaming conversation. +Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. +Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. +Reference.

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      diff --git a/docs/reference/web/chat_stream.html b/docs/reference/web/chat_stream.html index 2f4dea425..71715bd93 100644 --- a/docs/reference/web/chat_stream.html +++ b/docs/reference/web/chat_stream.html @@ -58,7 +58,8 @@

      Classes

      class ChatStream:
           """A helper class for streaming markdown text into a conversation using the chat streaming APIs.
       
      -    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.
      +    This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API
      +    methods, with automatic buffering and state management.
           """
       
           def __init__(
      @@ -81,10 +82,14 @@ 

      Classes

      client: The WebClient instance to use for API calls. channel: An encoded ID that represents a channel, private group, or DM. logger: A logging channel for outputs. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -110,10 +115,12 @@

      Classes

      ) -> Optional[SlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -165,8 +172,10 @@

      Classes

      Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -238,7 +247,8 @@

      Classes

      return response

      A helper class for streaming markdown text into a conversation using the chat streaming APIs.

      -

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management.

      +

      This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API +methods, with automatic buffering and state management.

      Initialize a new ChatStream instance.

      The init method creates a unique ChatStream instance that keeps track of one chat stream.

      Args

      @@ -250,13 +260,17 @@

      Args

      logger
      A logging channel for outputs.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      **kwargs
      Additional arguments passed to the underlying API calls.
      @@ -278,10 +292,12 @@

      Methods

      ) -> Optional[SlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -322,11 +338,13 @@

      Methods

      return None

      Append to the stream.

      -

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called.

      +

      The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream +is stopped this method cannot be called.

      Args

      markdown_text
      -
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is +what will be appended to the message received so far.
      **kwargs
      Additional arguments passed to the underlying API calls.
      @@ -369,8 +387,10 @@

      Example

      Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -425,9 +445,11 @@

      Args

      blocks
      A list of blocks that will be rendered at the bottom of the finalized message.
      markdown_text
      -
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.
      +
      Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is +what will be appended to the message received so far.
      metadata
      -
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
      +
      JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you +post to Slack is accessible to any app or user who is a member of that workspace.
      **kwargs
      Additional arguments passed to the underlying API calls.
      diff --git a/docs/reference/web/client.html b/docs/reference/web/client.html index 886ada4ad..45e573e71 100644 --- a/docs/reference/web/client.html +++ b/docs/reference/web/client.html @@ -2926,6 +2926,32 @@

      Classes

      kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stopStream( + self, + *, + channel: str, + ts: str, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> SlackResponse: + """Stops a streaming conversation. + https://api.slack.com/methods/chat.stopStream + """ + kwargs.update( + { + "channel": channel, + "ts": ts, + "markdown_text": markdown_text, + "blocks": blocks, + "metadata": metadata, + } + ) + _parse_web_class_objects(kwargs) + kwargs = _remove_none_values(kwargs) + return self.api_call("chat.stopStream", json=kwargs) + def chat_stream( self, *, @@ -2938,19 +2964,27 @@

      Classes

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -2981,32 +3015,6 @@

      Classes

      **kwargs, ) - def chat_stopStream( - self, - *, - channel: str, - ts: str, - markdown_text: Optional[str] = None, - blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, - metadata: Optional[Union[Dict, Metadata]] = None, - **kwargs, - ) -> SlackResponse: - """Stops a streaming conversation. - https://api.slack.com/methods/chat.stopStream - """ - kwargs.update( - { - "channel": channel, - "ts": ts, - "markdown_text": markdown_text, - "blocks": blocks, - "metadata": metadata, - } - ) - _parse_web_class_objects(kwargs) - kwargs = _remove_none_values(kwargs) - return self.api_call("chat.stopStream", json=kwargs) - def chat_unfurl( self, *, @@ -10317,19 +10325,27 @@

      Methods

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -10361,23 +10377,31 @@

      Methods

      )

      Stream markdown text into a conversation.

      -

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, +the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      The following methods are used:

        -
      • chat.startStream: Starts a new streaming conversation. Reference.
      • -
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • -
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +
      • chat.startStream: Starts a new streaming conversation. +Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. +Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. +Reference.

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html index 3a8f81cc6..05fd3d7d6 100644 --- a/docs/reference/web/index.html +++ b/docs/reference/web/index.html @@ -3295,6 +3295,32 @@

      Raises

      kwargs = _remove_none_values(kwargs) return self.api_call("chat.startStream", json=kwargs) + def chat_stopStream( + self, + *, + channel: str, + ts: str, + markdown_text: Optional[str] = None, + blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, + metadata: Optional[Union[Dict, Metadata]] = None, + **kwargs, + ) -> SlackResponse: + """Stops a streaming conversation. + https://api.slack.com/methods/chat.stopStream + """ + kwargs.update( + { + "channel": channel, + "ts": ts, + "markdown_text": markdown_text, + "blocks": blocks, + "metadata": metadata, + } + ) + _parse_web_class_objects(kwargs) + kwargs = _remove_none_values(kwargs) + return self.api_call("chat.stopStream", json=kwargs) + def chat_stream( self, *, @@ -3307,19 +3333,27 @@

      Raises

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -3350,32 +3384,6 @@

      Raises

      **kwargs, ) - def chat_stopStream( - self, - *, - channel: str, - ts: str, - markdown_text: Optional[str] = None, - blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, - metadata: Optional[Union[Dict, Metadata]] = None, - **kwargs, - ) -> SlackResponse: - """Stops a streaming conversation. - https://api.slack.com/methods/chat.stopStream - """ - kwargs.update( - { - "channel": channel, - "ts": ts, - "markdown_text": markdown_text, - "blocks": blocks, - "metadata": metadata, - } - ) - _parse_web_class_objects(kwargs) - kwargs = _remove_none_values(kwargs) - return self.api_call("chat.stopStream", json=kwargs) - def chat_unfurl( self, *, @@ -10686,19 +10694,27 @@

      Methods

      ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. @@ -10730,23 +10746,31 @@

      Methods

      )

      Stream markdown text into a conversation.

      -

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      +

      This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, +the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.

      The following methods are used:

        -
      • chat.startStream: Starts a new streaming conversation. Reference.
      • -
      • chat.appendStream: Appends text to an existing streaming conversation. Reference.
      • -
      • chat.stopStream: Stops a streaming conversation. Reference.
      • +
      • chat.startStream: Starts a new streaming conversation. +Reference.
      • +
      • chat.appendStream: Appends text to an existing streaming conversation. +Reference.
      • +
      • chat.stopStream: Stops a streaming conversation. +Reference.

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. +Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      -
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user request.
      +
      Provide another message's ts value to reply to. Streamed messages should always be replies to a user +request.
      recipient_team_id
      -
      The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.
      +
      The encoded ID of the team the user receiving the streaming text belongs to. Required when +streaming to channels.
      recipient_user_id
      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      **kwargs
      diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py index a94c8d00b..85696598b 100644 --- a/slack_sdk/web/async_chat_stream.py +++ b/slack_sdk/web/async_chat_stream.py @@ -24,7 +24,8 @@ class AsyncChatStream: """A helper class for streaming markdown text into a conversation using the chat streaming APIs. - This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management. + This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API + methods, with automatic buffering and state management. """ def __init__( @@ -47,10 +48,14 @@ def __init__( client: The WebClient instance to use for API calls. channel: An encoded ID that represents a channel, private group, or DM. logger: A logging channel for outputs. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -76,10 +81,12 @@ async def append( ) -> Optional[AsyncSlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -131,8 +138,10 @@ async def stop( Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index 54146d590..aead149cd 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -2943,19 +2943,27 @@ async def chat_stream( ) -> AsyncChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py index 47d77b450..8b2f3bb9b 100644 --- a/slack_sdk/web/chat_stream.py +++ b/slack_sdk/web/chat_stream.py @@ -14,7 +14,8 @@ class ChatStream: """A helper class for streaming markdown text into a conversation using the chat streaming APIs. - This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API methods, with automatic buffering and state management. + This class provides a convenient interface for the chat.startStream, chat.appendStream, and chat.stopStream API + methods, with automatic buffering and state management. """ def __init__( @@ -37,10 +38,14 @@ def __init__( client: The WebClient instance to use for API calls. channel: An encoded ID that represents a channel, private group, or DM. logger: A logging channel for outputs. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -66,10 +71,12 @@ def append( ) -> Optional[SlackResponse]: """Append to the stream. - The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. + The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream + is stopped this method cannot be called. Args: - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. **kwargs: Additional arguments passed to the underlying API calls. Returns: @@ -121,8 +128,10 @@ def stop( Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. - markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far. - metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. + markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is + what will be appended to the message received so far. + metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you + post to Slack is accessible to any app or user who is a member of that workspace. **kwargs: Additional arguments passed to the underlying API calls. Returns: diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index a1bb4397b..cc09df3fe 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -2933,19 +2933,27 @@ def chat_stream( ) -> ChatStream: """Stream markdown text into a conversation. - This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. + This method starts a new chat stream in a coversation that can be appended to. After appending an entire message, + the stream can be stopped with concluding arguments such as "blocks" for gathering feedback. The following methods are used: - - chat.startStream: Starts a new streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.startStream). - - chat.appendStream: Appends text to an existing streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). - - chat.stopStream: Stops a streaming conversation. [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). + - chat.startStream: Starts a new streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.startStream). + - chat.appendStream: Appends text to an existing streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.appendStream). + - chat.stopStream: Stops a streaming conversation. + [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. + Default: 256. channel: An encoded ID that represents a channel, private group, or DM. - thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. - recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels. + thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user + request. + recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when + streaming to channels. recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. **kwargs: Additional arguments passed to the underlying API calls. From a962196ad16522a70093dcc79feac85be5d2fd18 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 16:38:58 -0700 Subject: [PATCH 13/18] style: codegen without changing legacy client --- scripts/codegen.py | 2 +- slack_sdk/web/legacy_client.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/codegen.py b/scripts/codegen.py index 53b6d65e4..3633faf35 100644 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -119,7 +119,7 @@ legacy_source, ) legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source) - legacy_source = re.sub(r"from slack_sdk.web.chat_stream import ChatStream", "", legacy_source) + legacy_source = re.sub(r"^from slack_sdk.web.chat_stream import ChatStream\n", "", legacy_source, flags=re.MULTILINE) legacy_source = re.sub(r"(?s)def chat_stream.*?(?=def)", "", legacy_source) with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output: output.write(legacy_source) diff --git a/slack_sdk/web/legacy_client.py b/slack_sdk/web/legacy_client.py index 1eeee1f40..29ef99064 100644 --- a/slack_sdk/web/legacy_client.py +++ b/slack_sdk/web/legacy_client.py @@ -21,7 +21,6 @@ import slack_sdk.errors as e from slack_sdk.models.views import View - from ..models.attachments import Attachment from ..models.blocks import Block from ..models.metadata import Metadata From 82d1495f139b2f4f51f51bf594d30db1bc0e33a8 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 1 Oct 2025 19:48:56 -0700 Subject: [PATCH 14/18] test: remove codegen reminent --- tests/slack_sdk/web/test_chat_stream.py | 4 ---- tests/slack_sdk_async/web/test_async_chat_stream.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/tests/slack_sdk/web/test_chat_stream.py b/tests/slack_sdk/web/test_chat_stream.py index d9571f44f..596e9c84a 100644 --- a/tests/slack_sdk/web/test_chat_stream.py +++ b/tests/slack_sdk/web/test_chat_stream.py @@ -1,5 +1,4 @@ import json -import re import unittest from urllib.parse import parse_qs, urlparse @@ -79,9 +78,6 @@ def setUp(self): def tearDown(self): cleanup_mock_web_api_server(self) - pattern_for_language = re.compile("python/(\\S+)", re.IGNORECASE) - pattern_for_package_identifier = re.compile("slackclient/(\\S+)") - def test_streams_a_short_message(self): streamer = self.client.chat_stream( channel="C0123456789", diff --git a/tests/slack_sdk_async/web/test_async_chat_stream.py b/tests/slack_sdk_async/web/test_async_chat_stream.py index 48764c825..6eee84119 100644 --- a/tests/slack_sdk_async/web/test_async_chat_stream.py +++ b/tests/slack_sdk_async/web/test_async_chat_stream.py @@ -1,5 +1,4 @@ import json -import re import unittest from urllib.parse import parse_qs, urlparse @@ -80,9 +79,6 @@ def setUp(self): def tearDown(self): cleanup_mock_web_api_server(self) - pattern_for_language = re.compile("python/(\\S+)", re.IGNORECASE) - pattern_for_package_identifier = re.compile("slackclient/(\\S+)") - @async_test async def test_streams_a_short_message(self): streamer = await self.client.chat_stream( From dbe397fd1b95a7315a46b3531b08701b990fffa2 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Thu, 2 Oct 2025 09:37:51 -0700 Subject: [PATCH 15/18] docs: make the buffered methods clear in reference Co-authored-by: Michael Brooks --- slack_sdk/web/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index cc09df3fe..0cf6eb605 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -2946,7 +2946,7 @@ def chat_stream( [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. From 702e19cec6be9462688fc7d392b14dae6d114756 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Thu, 2 Oct 2025 09:42:05 -0700 Subject: [PATCH 16/18] docs: match correct defaults with linebreaks for lint --- slack_sdk/web/chat_stream.py | 1 - slack_sdk/web/client.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/slack_sdk/web/chat_stream.py b/slack_sdk/web/chat_stream.py index 8b2f3bb9b..1a379c9cb 100644 --- a/slack_sdk/web/chat_stream.py +++ b/slack_sdk/web/chat_stream.py @@ -45,7 +45,6 @@ def __init__( recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client diff --git a/slack_sdk/web/client.py b/slack_sdk/web/client.py index 0cf6eb605..f95a2a726 100644 --- a/slack_sdk/web/client.py +++ b/slack_sdk/web/client.py @@ -2946,9 +2946,9 @@ def chat_stream( [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. From dc88b0325d15d9b174a850860ca8bc891d54ba20 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Thu, 2 Oct 2025 09:56:48 -0700 Subject: [PATCH 17/18] docs: update generated docs --- docs/reference/index.html | 18 +++++++++--------- docs/reference/web/async_chat_stream.html | 4 +--- docs/reference/web/async_client.html | 18 +++++++++--------- docs/reference/web/chat_stream.html | 4 +--- docs/reference/web/client.html | 18 +++++++++--------- docs/reference/web/index.html | 18 +++++++++--------- slack_sdk/web/async_chat_stream.py | 1 - slack_sdk/web/async_client.py | 6 +++--- 8 files changed, 41 insertions(+), 46 deletions(-) diff --git a/docs/reference/index.html b/docs/reference/index.html index e7185c898..3cfd45f3f 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -3081,9 +3081,9 @@

      Classes

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10442,9 +10442,9 @@

      Methods

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10495,9 +10495,9 @@

      Methods

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a stream method. Increasing this +value decreases the number of method calls made for the same amount of text, which is useful to avoid rate +limits. Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      diff --git a/docs/reference/web/async_chat_stream.html b/docs/reference/web/async_chat_stream.html index 25240ef76..ca7bf2506 100644 --- a/docs/reference/web/async_chat_stream.html +++ b/docs/reference/web/async_chat_stream.html @@ -89,7 +89,6 @@

      Classes

      recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -269,8 +268,7 @@

      Args

      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits.
      **kwargs
      Additional arguments passed to the underlying API calls.
      diff --git a/docs/reference/web/async_client.html b/docs/reference/web/async_client.html index efec8c06e..7a46cf18c 100644 --- a/docs/reference/web/async_client.html +++ b/docs/reference/web/async_client.html @@ -2977,9 +2977,9 @@

      Classes

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10338,9 +10338,9 @@

      Methods

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10391,9 +10391,9 @@

      Methods

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a stream method. Increasing this +value decreases the number of method calls made for the same amount of text, which is useful to avoid rate +limits. Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      diff --git a/docs/reference/web/chat_stream.html b/docs/reference/web/chat_stream.html index 71715bd93..94d96e5eb 100644 --- a/docs/reference/web/chat_stream.html +++ b/docs/reference/web/chat_stream.html @@ -89,7 +89,6 @@

      Classes

      recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client @@ -269,8 +268,7 @@

      Args

      The encoded ID of the user to receive the streaming text. Required when streaming to channels.
      buffer_size
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits.
      **kwargs
      Additional arguments passed to the underlying API calls.
      diff --git a/docs/reference/web/client.html b/docs/reference/web/client.html index 45e573e71..162df0964 100644 --- a/docs/reference/web/client.html +++ b/docs/reference/web/client.html @@ -2977,9 +2977,9 @@

      Classes

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10338,9 +10338,9 @@

      Methods

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10391,9 +10391,9 @@

      Methods

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a stream method. Increasing this +value decreases the number of method calls made for the same amount of text, which is useful to avoid rate +limits. Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html index 05fd3d7d6..c2df7f11f 100644 --- a/docs/reference/web/index.html +++ b/docs/reference/web/index.html @@ -3346,9 +3346,9 @@

      Raises

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10707,9 +10707,9 @@

      Methods

      [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. @@ -10760,9 +10760,9 @@

      Methods

      Args

      buffer_size
      -
      The length of markdown_text to buffer in-memory before calling a method. Increasing this value -decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. -Default: 256.
      +
      The length of markdown_text to buffer in-memory before calling a stream method. Increasing this +value decreases the number of method calls made for the same amount of text, which is useful to avoid rate +limits. Default: 256.
      channel
      An encoded ID that represents a channel, private group, or DM.
      thread_ts
      diff --git a/slack_sdk/web/async_chat_stream.py b/slack_sdk/web/async_chat_stream.py index 85696598b..4661f19dd 100644 --- a/slack_sdk/web/async_chat_stream.py +++ b/slack_sdk/web/async_chat_stream.py @@ -55,7 +55,6 @@ def __init__( recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels. buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. **kwargs: Additional arguments passed to the underlying API calls. """ self._client = client diff --git a/slack_sdk/web/async_client.py b/slack_sdk/web/async_client.py index aead149cd..f4aa8a17f 100644 --- a/slack_sdk/web/async_client.py +++ b/slack_sdk/web/async_client.py @@ -2956,9 +2956,9 @@ async def chat_stream( [Reference](https://docs.slack.dev/reference/methods/chat.stopStream). Args: - buffer_size: The length of markdown_text to buffer in-memory before calling a method. Increasing this value - decreases the number of method calls made for the same amount of text, which is useful to avoid rate limits. - Default: 256. + buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this + value decreases the number of method calls made for the same amount of text, which is useful to avoid rate + limits. Default: 256. channel: An encoded ID that represents a channel, private group, or DM. thread_ts: Provide another message's ts value to reply to. Streamed messages should always be replies to a user request. From 38ec262cce8dc312d2167dbde582e62ea2b80ed7 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Thu, 2 Oct 2025 09:57:22 -0700 Subject: [PATCH 18/18] test: confirm context actions can be sent with stop --- tests/slack_sdk/web/test_chat_stream.py | 26 ++++++++++++++++++- .../web/test_async_chat_stream.py | 26 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tests/slack_sdk/web/test_chat_stream.py b/tests/slack_sdk/web/test_chat_stream.py index 596e9c84a..75c13c8c2 100644 --- a/tests/slack_sdk/web/test_chat_stream.py +++ b/tests/slack_sdk/web/test_chat_stream.py @@ -4,6 +4,9 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackRequestError +from slack_sdk.models.blocks.basic_components import FeedbackButtonObject +from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement +from slack_sdk.models.blocks.blocks import ContextActionsBlock from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server from tests.slack_sdk.web.mock_web_api_handler import MockHandler @@ -116,7 +119,24 @@ def test_streams_a_long_message(self): streamer.append(markdown_text="e is", token="xoxb-chat_stream_test_token1") streamer.append(markdown_text=" bold!") streamer.append(markdown_text="*") - streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token2") + streamer.stop( + blocks=[ + ContextActionsBlock( + elements=[ + FeedbackButtonsElement( + positive_button=FeedbackButtonObject(text="good", value="+1"), + negative_button=FeedbackButtonObject(text="bad", value="-1"), + ), + IconButtonElement( + icon="trash", + text="delete", + ), + ], + ) + ], + markdown_text="*", + token="xoxb-chat_stream_test_token2", + ) self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) @@ -137,6 +157,10 @@ def test_streams_a_long_message(self): self.assertEqual(append_request.get("ts"), "123.123") stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual( + json.dumps(stop_request.get("blocks")), + '[{"elements": [{"negative_button": {"text": {"emoji": true, "text": "bad", "type": "plain_text"}, "value": "-1"}, "positive_button": {"text": {"emoji": true, "text": "good", "type": "plain_text"}, "value": "+1"}, "type": "feedback_buttons"}, {"icon": "trash", "text": {"emoji": true, "text": "delete", "type": "plain_text"}, "type": "icon_button"}], "type": "context_actions"}]', + ) self.assertEqual(stop_request.get("channel"), "C0123456789") self.assertEqual(stop_request.get("markdown_text"), "**") self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token2") diff --git a/tests/slack_sdk_async/web/test_async_chat_stream.py b/tests/slack_sdk_async/web/test_async_chat_stream.py index 6eee84119..212fee1e2 100644 --- a/tests/slack_sdk_async/web/test_async_chat_stream.py +++ b/tests/slack_sdk_async/web/test_async_chat_stream.py @@ -3,6 +3,9 @@ from urllib.parse import parse_qs, urlparse from slack_sdk.errors import SlackRequestError +from slack_sdk.models.blocks.basic_components import FeedbackButtonObject +from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement +from slack_sdk.models.blocks.blocks import ContextActionsBlock from slack_sdk.web.async_client import AsyncWebClient from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server from tests.slack_sdk.web.mock_web_api_handler import MockHandler @@ -119,7 +122,24 @@ async def test_streams_a_long_message(self): await streamer.append(markdown_text="e is", token="xoxb-chat_stream_test_token1") await streamer.append(markdown_text=" bold!") await streamer.append(markdown_text="*") - await streamer.stop(markdown_text="*", token="xoxb-chat_stream_test_token2") + await streamer.stop( + blocks=[ + ContextActionsBlock( + elements=[ + FeedbackButtonsElement( + positive_button=FeedbackButtonObject(text="good", value="+1"), + negative_button=FeedbackButtonObject(text="bad", value="-1"), + ), + IconButtonElement( + icon="trash", + text="delete", + ), + ], + ) + ], + markdown_text="*", + token="xoxb-chat_stream_test_token2", + ) self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) @@ -140,6 +160,10 @@ async def test_streams_a_long_message(self): self.assertEqual(append_request.get("ts"), "123.123") stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) + self.assertEqual( + json.dumps(stop_request.get("blocks")), + '[{"elements": [{"negative_button": {"text": {"emoji": true, "text": "bad", "type": "plain_text"}, "value": "-1"}, "positive_button": {"text": {"emoji": true, "text": "good", "type": "plain_text"}, "value": "+1"}, "type": "feedback_buttons"}, {"icon": "trash", "text": {"emoji": true, "text": "delete", "type": "plain_text"}, "type": "icon_button"}], "type": "context_actions"}]', + ) self.assertEqual(stop_request.get("channel"), "C0123456789") self.assertEqual(stop_request.get("markdown_text"), "**") self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token2")