From 4bcb4db987a81098c346947a8ba0d43e4bb8b196 Mon Sep 17 00:00:00 2001 From: Luke Russell Date: Fri, 3 Oct 2025 11:31:42 -0700 Subject: [PATCH 1/5] go --- docs/english/web.md | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/docs/english/web.md b/docs/english/web.md index 5069e5461..5acabdbef 100644 --- a/docs/english/web.md +++ b/docs/english/web.md @@ -33,6 +33,8 @@ except SlackApiError as e: assert e.response["error"] # str like 'invalid_auth', 'channel_not_found' ``` +### Sending ephemeral messages + Sending an ephemeral message, which is only visible to an assigned user in a specified channel, is nearly the same as sending a regular message but with an additional `user` parameter. ``` python @@ -51,6 +53,110 @@ response = client.chat_postEphemeral( See the [`chat.postEphemeral`](/reference/methods/chat.postEphemeral) API method for more details. +### Sending streaming messages {#sending-streaming-messages} + +You can have your app's messages stream in to replicate conventional AI chatbot behavior. This is done through three Web API methods: + +* [`chat_startStream`](/reference/methods/chat.startstream) +* [`chat_appendStream`](/reference/methods/chat.appendstream) +* [`chat_stopStream`](/reference/methods/chat.stopstream) + +:::tip [The Python Slack SDK provides a [`chat_stream()`](https://docss.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] + +See the [_Streaming messages_](/tools/bolt-python/concepts/message-sendin#streaming-messages) section of the Bolt for Python docs for implementation instructions. + +::: + +#### Starting the message stream + +First you need to begin the message stream: + +```python +# Example: Stream a response to any message +@app.message() +def handle_message(message, client): + channel_id = payload["channel"] + thread_ts = payload["thread_ts"] + + # Start a new message stream + stream_response = client.chat_startStream( + channel=channel_id, + thread_ts=thread_ts, + ) + stream_ts = stream_response["ts"] +``` + +#### Appending content to the message stream + +With the stream started, you can then append text to it in chunks to convey a streaming effect. + +The structure of the text coming in will depend on your source. The following code snippet uses OpenAI's response structure as an example: + +```python +# continued from above + for event in returned_message: + if event.type == "response.output_text.delta": + client.chat_appendStream( + channel=channel_id, + ts=stream_ts, + markdown_text=f"{event.delta}" + ) + else: + continue +``` + +#### Finishing the message stream + +Your app can then end the stream with the `chat_stopStream` method: + +```python +# continued from above + client.chat_stopStream( + channel=channel_id, + ts=stream_ts + ) +``` + +The method also provides you an opportunity to request user feedback on your app's responses using the [feedback buttons](/reference/block-kit/block-elements/feedback-buttons-element) block element within the [context actions](/reference/block-kit/blocks/context-actions-block) block. The user will be presented with thumbs up and thumbs down buttons. + +```python +def create_feedback_block() -> List[Block]: + blocks: List[Block] = [ + ContextActionsBlock( + elements=[ + FeedbackButtonsElement( + action_id="feedback", + positive_button=FeedbackButtonObject( + text="Good Response", + accessibility_label="Submit positive feedback on this response", + value="good-feedback", + ), + negative_button=FeedbackButtonObject( + text="Bad Response", + accessibility_label="Submit negative feedback on this response", + value="bad-feedback", + ), + ) + ] + ) + ] + return blocks + +@app.message() +def handle_message(message, client): + # ... previous streaming code ... + + # Stop the stream and add interactive elements + feedback_block = create_feedback_block() + client.chat_stopStream( + channel=channel_id, + ts=stream_ts, + blocks=feedback_block + ) +``` + +See [Formatting messages with Block Kit](#block-kit) below for more details on using Block Kit with messages. + ## Formatting messages with Block Kit {#block-kit} Messages posted from apps can contain more than just text; they can also include full user interfaces composed of blocks using [Block Kit](/block-kit). From 0b4beb2b2008fa682346e8be81246015b673ad9b Mon Sep 17 00:00:00 2001 From: Luke Russell Date: Fri, 3 Oct 2025 11:49:18 -0700 Subject: [PATCH 2/5] typo --- docs/english/web.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/english/web.md b/docs/english/web.md index 5acabdbef..6e6258c51 100644 --- a/docs/english/web.md +++ b/docs/english/web.md @@ -63,7 +63,7 @@ You can have your app's messages stream in to replicate conventional AI chatbot :::tip [The Python Slack SDK provides a [`chat_stream()`](https://docss.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] -See the [_Streaming messages_](/tools/bolt-python/concepts/message-sendin#streaming-messages) section of the Bolt for Python docs for implementation instructions. +See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#streaming-messages) section of the Bolt for Python docs for implementation instructions. ::: From ad64e7d5c7efdd6b389aad7fbb694c8cf95c7cc8 Mon Sep 17 00:00:00 2001 From: Luke Russell Date: Fri, 3 Oct 2025 11:55:02 -0700 Subject: [PATCH 3/5] go --- docs/english/web.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/english/web.md b/docs/english/web.md index 6e6258c51..90dd1f5ac 100644 --- a/docs/english/web.md +++ b/docs/english/web.md @@ -67,7 +67,7 @@ See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#strea ::: -#### Starting the message stream +#### Starting the message stream {#starting-stream} First you need to begin the message stream: @@ -86,7 +86,7 @@ def handle_message(message, client): stream_ts = stream_response["ts"] ``` -#### Appending content to the message stream +#### Appending content to the message stream {#appending-stream} With the stream started, you can then append text to it in chunks to convey a streaming effect. @@ -105,7 +105,7 @@ The structure of the text coming in will depend on your source. The following co continue ``` -#### Finishing the message stream +#### Stopping the message stream {#stopping-stream} Your app can then end the stream with the `chat_stopStream` method: From c3e472a47519845c7a4c8efafd7832a09ead88c0 Mon Sep 17 00:00:00 2001 From: Luke Russell <31357343+lukegalbraithrussell@users.noreply.github.com> Date: Fri, 3 Oct 2025 12:58:06 -0700 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Eden Zimbelman --- docs/english/web.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/english/web.md b/docs/english/web.md index 90dd1f5ac..19703fbb6 100644 --- a/docs/english/web.md +++ b/docs/english/web.md @@ -61,7 +61,7 @@ You can have your app's messages stream in to replicate conventional AI chatbot * [`chat_appendStream`](/reference/methods/chat.appendstream) * [`chat_stopStream`](/reference/methods/chat.stopstream) -:::tip [The Python Slack SDK provides a [`chat_stream()`](https://docss.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] +:::tip [The Python Slack SDK provides a [`chat_stream()`](/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#streaming-messages) section of the Bolt for Python docs for implementation instructions. @@ -75,12 +75,16 @@ First you need to begin the message stream: # Example: Stream a response to any message @app.message() def handle_message(message, client): - channel_id = payload["channel"] - thread_ts = payload["thread_ts"] + channel_id = event.get("channel") + team_id = event.get("team") + thread_ts = event.get("thread_ts") or event.get("ts") + user_id = event.get("user") # Start a new message stream stream_response = client.chat_startStream( channel=channel_id, + recipient_team_id=team_id, + recipient_user_id=user_id, thread_ts=thread_ts, ) stream_ts = stream_response["ts"] @@ -117,7 +121,7 @@ Your app can then end the stream with the `chat_stopStream` method: ) ``` -The method also provides you an opportunity to request user feedback on your app's responses using the [feedback buttons](/reference/block-kit/block-elements/feedback-buttons-element) block element within the [context actions](/reference/block-kit/blocks/context-actions-block) block. The user will be presented with thumbs up and thumbs down buttons. +The method also provides you an opportunity to request user feedback on your app's responses using the [feedback buttons](/reference/block-kit/block-elements/feedback-buttons-element) block element within the [context actions](/reference/block-kit/blocks/context-actions-block) block. The user will be presented with thumbs up and thumbs down buttons which send an action to your app when pressed. ```python def create_feedback_block() -> List[Block]: From 9064ee0a801fea18c44e0f2e4379ed0be9066895 Mon Sep 17 00:00:00 2001 From: Luke Russell Date: Fri, 3 Oct 2025 12:58:53 -0700 Subject: [PATCH 5/5] full path --- docs/english/web.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/english/web.md b/docs/english/web.md index 19703fbb6..0b689c530 100644 --- a/docs/english/web.md +++ b/docs/english/web.md @@ -61,7 +61,7 @@ You can have your app's messages stream in to replicate conventional AI chatbot * [`chat_appendStream`](/reference/methods/chat.appendstream) * [`chat_stopStream`](/reference/methods/chat.stopstream) -:::tip [The Python Slack SDK provides a [`chat_stream()`](/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] +:::tip [The Python Slack SDK provides a [`chat_stream()`](https://docs.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.] See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#streaming-messages) section of the Bolt for Python docs for implementation instructions.