You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can have your app's messages stream in to replicate conventional AI chatbot behavior. This is done through three Web API methods:
46
+
You can have your app's messages stream in to replicate conventional agent behavior. Bolt for Python provides a `say_stream` utility as a listener argument available for `app.event` and `app.message` listeners.
The `say_stream` utility streamlines calling the Python Slack SDK's [`WebClient.chat_stream`](https://docs.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility by sourcing parameter values from the relevant event payload.
51
49
52
-
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):
50
+
| Parameter | Value |
51
+
|---|---|
52
+
| `channel_id` | Sourced from the event payload.
53
+
| `thread_ts` | Sourced from the event payload. Falls back to the `ts` value if available.
54
+
| `recipient_team_id` | Sourced from the event `team_id` (`enterprise_id` if the app is installed on an org).
55
+
| `recipient_user_id` | Sourced from the `user_id` of the event.
If neither a `channel_id` or `thread_ts` can be sourced, then the utility will merely be `None`.
58
+
59
+
For information on calling the `chat_*Stream` API methods directly, see the [_Sending streaming messages_](/tools/python-slack-sdk/web#sending-streaming-messages) section of the Python Slack SDK docs.
60
+
61
+
### Example {#example}
62
+
63
+
```py
64
+
import os
65
+
66
+
from slack_bolt import App, SayStream
67
+
from slack_bolt.adapter.socket_mode import SocketModeHandler
In that example, a [feedback buttons](/reference/block-kit/block-elements/feedback-buttons-element) block element is passed to `streamer.stop` to provide feedback buttons to the user at the bottom of the message. Interaction with these buttons will send a block action event to your app to receive the feedback.
89
+
#### Adding feedback buttons after a stream
75
90
76
-
```python
91
+
You can pass a [feedback buttons](/reference/block-kit/block-elements/feedback-buttons-element) block element to `stream.stop` to provide feedback buttons to the user at the bottom of the message. Interaction with these buttons will send a block action event to your app to receive the feedback.
For information on calling the `chat_*Stream` API methods without the helper utility, see the [_Sending streaming messages_](/tools/python-slack-sdk/web#sending-streaming-messages) section of the Python Slack SDK docs.
The `chat_stream()` method currently only works when the `thread_ts` field is available in the event context (DMs and threaded replies). Top-level channel messages do not have a `thread_ts` field, and the `ts` field is not yet provided to `BoltAgent`.
0 commit comments