Skip to content

Commit 2f707b0

Browse files
go
1 parent 3e65b9b commit 2f707b0

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

docs/english/web.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ You can have your app's messages stream in to replicate conventional AI chatbot
6161
* [`chat_appendStream`](/reference/methods/chat.appendStream)
6262
* [`chat_stopStream`](/reference/methods/chat.stopStream)
6363

64-
:::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.]
6564

66-
See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#streaming-messages) section of the Bolt for Python docs for implementation instructions.
67-
68-
:::
65+
You can streamline calling these methods by using the [`chat_stream()`](#chat_stream) helper.
6966

7067
#### Starting the message stream {#starting-stream}
7168

@@ -161,6 +158,30 @@ def handle_message(message, client):
161158

162159
See [Formatting messages with Block Kit](#block-kit) below for more details on using Block Kit with messages.
163160

161+
#### Using the `chat_stream()` helper {#chat_stream}
162+
163+
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. Here's an excerpt from our [Assistant template app](https://github.com/slack-samples/bolt-python-assistant-template):
164+
165+
```python
166+
streamer = client.chat_stream(
167+
channel=channel_id,
168+
recipient_team_id=team_id,
169+
recipient_user_id=user_id,
170+
thread_ts=thread_ts,
171+
)
172+
173+
# Loop over OpenAI response stream
174+
# https://platform.openai.com/docs/api-reference/responses/create
175+
for event in returned_message:
176+
if event.type == "response.output_text.delta":
177+
streamer.append(markdown_text=f"{event.delta}")
178+
else:
179+
continue
180+
181+
feedback_block = create_feedback_block()
182+
streamer.stop()
183+
```
184+
164185
## Formatting messages with Block Kit {#block-kit}
165186

166187
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).

0 commit comments

Comments
 (0)