Skip to content

Commit 422c62f

Browse files
just docs
1 parent 785b813 commit 422c62f

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

docs/english/_sidebar.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@
8585
"tools/bolt-python/concepts/token-rotation"
8686
]
8787
},
88-
{
89-
"type": "category",
90-
"label": "Experiments",
91-
"items": ["tools/bolt-python/experiments"]
92-
},
88+
"tools/bolt-python/experiments",
9389
{
9490
"type": "category",
9591
"label": "Legacy",

docs/english/experiments.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ We love feedback from our community, so we encourage you to explore and interact
88

99
## Available experiments
1010
* [Agent listener argument](#agent)
11+
* [`say_stream` utility](#say-stream)
1112

1213
## Agent listener argument {#agent}
1314

@@ -31,4 +32,47 @@ def handle_mention(agent: BoltAgent):
3132

3233
### Limitations
3334

34-
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`.
35+
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`.
36+
37+
## `say_stream` utility {#say-stream}
38+
39+
The `say_stream` utility is a listener argument available on `app.event` and `app.message` listeners.
40+
41+
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.
42+
43+
| Parameter | Value |
44+
|---|---|
45+
| `channel_id` | Sourced from the event payload.
46+
| `thread_ts` | Sourced from the event payload. Falls back to the `ts` value if available.
47+
| `recipient_team_id` | Sourced from the event `team_id` (`enterprise_id` if the app is installed on an org).
48+
| `recipient_user_id` | Sourced from the `user_id` of the event.
49+
50+
If neither a `channel_id` or `thread_ts` can be sourced, then the utility will merely be `None`.
51+
52+
### Example {#example}
53+
54+
```py
55+
import os
56+
57+
from slack_bolt import App, SayStream
58+
from slack_bolt.adapter.socket_mode import SocketModeHandler
59+
from slack_sdk import WebClient
60+
61+
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
62+
63+
@app.event("app_mention")
64+
def handle_app_mention(client: WebClient, say_stream: SayStream):
65+
stream = say_stream()
66+
stream.append(markdown_text="Someone rang the bat signal!")
67+
stream.stop()
68+
69+
@app.message("")
70+
def handle_message(client: WebClient, say_stream: SayStream):
71+
stream = say_stream()
72+
73+
stream.append(markdown_text="Let me consult my *vast knowledge database*...)
74+
stream.stop()
75+
76+
if __name__ == "__main__":
77+
SocketModeHandler(app, os.environ.get("SLACK_APP_TOKEN")).start()
78+
```

0 commit comments

Comments
 (0)