Skip to content

Commit 34530f7

Browse files
Merge branch 'main' into docs-say_stream-docs
2 parents 422c62f + ba7df02 commit 34530f7

28 files changed

+1373
-39
lines changed

slack_bolt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .context.fail import Fail
1515
from .context.respond import Respond
1616
from .context.say import Say
17+
from .context.say_stream import SayStream
1718
from .kwargs_injection import Args
1819
from .listener import Listener
1920
from .listener_matcher import CustomListenerMatcher
@@ -42,6 +43,7 @@
4243
"Fail",
4344
"Respond",
4445
"Say",
46+
"SayStream",
4547
"Args",
4648
"Listener",
4749
"CustomListenerMatcher",

slack_bolt/async_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ async def command(ack, body, respond):
5959
from .context.set_suggested_prompts.async_set_suggested_prompts import AsyncSetSuggestedPrompts
6060
from .context.get_thread_context.async_get_thread_context import AsyncGetThreadContext
6161
from .context.save_thread_context.async_save_thread_context import AsyncSaveThreadContext
62+
from .context.say_stream.async_say_stream import AsyncSayStream
6263

6364
__all__ = [
6465
"AsyncApp",
6566
"AsyncAck",
6667
"AsyncBoltContext",
6768
"AsyncRespond",
6869
"AsyncSay",
70+
"AsyncSayStream",
6971
"AsyncListener",
7072
"AsyncCustomListenerMatcher",
7173
"AsyncBoltRequest",

slack_bolt/context/assistant/assistant_utilities.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Optional
23

34
from slack_sdk.web import WebClient
@@ -51,6 +52,13 @@ def is_valid(self) -> bool:
5152

5253
@property
5354
def set_status(self) -> SetStatus:
55+
warnings.warn(
56+
"AssistantUtilities.set_status is deprecated. "
57+
"Use the set_status argument directly in your listener function "
58+
"or access it via context.set_status instead.",
59+
DeprecationWarning,
60+
stacklevel=2,
61+
)
5462
return SetStatus(self.client, self.channel_id, self.thread_ts)
5563

5664
@property

slack_bolt/context/assistant/async_assistant_utilities.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Optional
23

34
from slack_sdk.web.async_client import AsyncWebClient
@@ -54,6 +55,13 @@ def is_valid(self) -> bool:
5455

5556
@property
5657
def set_status(self) -> AsyncSetStatus:
58+
warnings.warn(
59+
"AsyncAssistantUtilities.set_status is deprecated. "
60+
"Use the set_status argument directly in your listener function "
61+
"or access it via context.set_status instead.",
62+
DeprecationWarning,
63+
stacklevel=2,
64+
)
5765
return AsyncSetStatus(self.client, self.channel_id, self.thread_ts)
5866

5967
@property

slack_bolt/context/async_context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from slack_bolt.context.get_thread_context.async_get_thread_context import AsyncGetThreadContext
1111
from slack_bolt.context.save_thread_context.async_save_thread_context import AsyncSaveThreadContext
1212
from slack_bolt.context.say.async_say import AsyncSay
13+
from slack_bolt.context.say_stream.async_say_stream import AsyncSayStream
1314
from slack_bolt.context.set_status.async_set_status import AsyncSetStatus
1415
from slack_bolt.context.set_suggested_prompts.async_set_suggested_prompts import AsyncSetSuggestedPrompts
1516
from slack_bolt.context.set_title.async_set_title import AsyncSetTitle
@@ -203,6 +204,10 @@ def set_suggested_prompts(self) -> Optional[AsyncSetSuggestedPrompts]:
203204
def get_thread_context(self) -> Optional[AsyncGetThreadContext]:
204205
return self.get("get_thread_context")
205206

207+
@property
208+
def say_stream(self) -> Optional[AsyncSayStream]:
209+
return self.get("say_stream")
210+
206211
@property
207212
def save_thread_context(self) -> Optional[AsyncSaveThreadContext]:
208213
return self.get("save_thread_context")

slack_bolt/context/base_context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class BaseContext(dict):
3838
"set_status",
3939
"set_title",
4040
"set_suggested_prompts",
41+
"say_stream",
4142
]
4243
# Note that these items are not copyable, so when you add new items to this list,
4344
# you must modify ThreadListenerRunner/AsyncioListenerRunner's _build_lazy_request method to pass the values.

slack_bolt/context/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from slack_bolt.context.respond import Respond
1111
from slack_bolt.context.save_thread_context import SaveThreadContext
1212
from slack_bolt.context.say import Say
13+
from slack_bolt.context.say_stream import SayStream
1314
from slack_bolt.context.set_status import SetStatus
1415
from slack_bolt.context.set_suggested_prompts import SetSuggestedPrompts
1516
from slack_bolt.context.set_title import SetTitle
@@ -204,6 +205,10 @@ def set_suggested_prompts(self) -> Optional[SetSuggestedPrompts]:
204205
def get_thread_context(self) -> Optional[GetThreadContext]:
205206
return self.get("get_thread_context")
206207

208+
@property
209+
def say_stream(self) -> Optional[SayStream]:
210+
return self.get("say_stream")
211+
207212
@property
208213
def save_thread_context(self) -> Optional[SaveThreadContext]:
209214
return self.get("save_thread_context")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Don't add async module imports here
2+
from .say_stream import SayStream
3+
4+
__all__ = [
5+
"SayStream",
6+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import warnings
2+
from typing import Optional
3+
4+
from slack_sdk.web.async_client import AsyncWebClient
5+
from slack_sdk.web.async_chat_stream import AsyncChatStream
6+
7+
from slack_bolt.warning import ExperimentalWarning
8+
9+
10+
class AsyncSayStream:
11+
client: AsyncWebClient
12+
channel: Optional[str]
13+
recipient_team_id: Optional[str]
14+
recipient_user_id: Optional[str]
15+
thread_ts: Optional[str]
16+
17+
def __init__(
18+
self,
19+
*,
20+
client: AsyncWebClient,
21+
channel: Optional[str] = None,
22+
recipient_team_id: Optional[str] = None,
23+
recipient_user_id: Optional[str] = None,
24+
thread_ts: Optional[str] = None,
25+
):
26+
self.client = client
27+
self.channel = channel
28+
self.recipient_team_id = recipient_team_id
29+
self.recipient_user_id = recipient_user_id
30+
self.thread_ts = thread_ts
31+
32+
async def __call__(
33+
self,
34+
*,
35+
buffer_size: Optional[int] = None,
36+
channel: Optional[str] = None,
37+
recipient_team_id: Optional[str] = None,
38+
recipient_user_id: Optional[str] = None,
39+
thread_ts: Optional[str] = None,
40+
**kwargs,
41+
) -> AsyncChatStream:
42+
"""Starts a new chat stream with context.
43+
44+
Warning: This is an experimental feature and may change in future versions.
45+
"""
46+
warnings.warn(
47+
"say_stream is experimental and may change in future versions.",
48+
category=ExperimentalWarning,
49+
stacklevel=2,
50+
)
51+
52+
channel = channel or self.channel
53+
thread_ts = thread_ts or self.thread_ts
54+
if channel is None:
55+
raise ValueError("say_stream without channel here is unsupported")
56+
if thread_ts is None:
57+
raise ValueError("say_stream without thread_ts here is unsupported")
58+
59+
if buffer_size is not None:
60+
return await self.client.chat_stream(
61+
buffer_size=buffer_size,
62+
channel=channel,
63+
recipient_team_id=recipient_team_id or self.recipient_team_id,
64+
recipient_user_id=recipient_user_id or self.recipient_user_id,
65+
thread_ts=thread_ts,
66+
**kwargs,
67+
)
68+
return await self.client.chat_stream(
69+
channel=channel,
70+
recipient_team_id=recipient_team_id or self.recipient_team_id,
71+
recipient_user_id=recipient_user_id or self.recipient_user_id,
72+
thread_ts=thread_ts,
73+
**kwargs,
74+
)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import warnings
2+
from typing import Optional
3+
4+
from slack_sdk import WebClient
5+
from slack_sdk.web.chat_stream import ChatStream
6+
7+
from slack_bolt.warning import ExperimentalWarning
8+
9+
10+
class SayStream:
11+
client: WebClient
12+
channel: Optional[str]
13+
recipient_team_id: Optional[str]
14+
recipient_user_id: Optional[str]
15+
thread_ts: Optional[str]
16+
17+
def __init__(
18+
self,
19+
*,
20+
client: WebClient,
21+
channel: Optional[str] = None,
22+
recipient_team_id: Optional[str] = None,
23+
recipient_user_id: Optional[str] = None,
24+
thread_ts: Optional[str] = None,
25+
):
26+
self.client = client
27+
self.channel = channel
28+
self.recipient_team_id = recipient_team_id
29+
self.recipient_user_id = recipient_user_id
30+
self.thread_ts = thread_ts
31+
32+
def __call__(
33+
self,
34+
*,
35+
buffer_size: Optional[int] = None,
36+
channel: Optional[str] = None,
37+
recipient_team_id: Optional[str] = None,
38+
recipient_user_id: Optional[str] = None,
39+
thread_ts: Optional[str] = None,
40+
**kwargs,
41+
) -> ChatStream:
42+
"""Starts a new chat stream with context.
43+
44+
Warning: This is an experimental feature and may change in future versions.
45+
"""
46+
warnings.warn(
47+
"say_stream is experimental and may change in future versions.",
48+
category=ExperimentalWarning,
49+
stacklevel=2,
50+
)
51+
52+
channel = channel or self.channel
53+
thread_ts = thread_ts or self.thread_ts
54+
if channel is None:
55+
raise ValueError("say_stream without channel here is unsupported")
56+
if thread_ts is None:
57+
raise ValueError("say_stream without thread_ts here is unsupported")
58+
59+
if buffer_size is not None:
60+
return self.client.chat_stream(
61+
buffer_size=buffer_size,
62+
channel=channel,
63+
recipient_team_id=recipient_team_id or self.recipient_team_id,
64+
recipient_user_id=recipient_user_id or self.recipient_user_id,
65+
thread_ts=thread_ts,
66+
**kwargs,
67+
)
68+
return self.client.chat_stream(
69+
channel=channel,
70+
recipient_team_id=recipient_team_id or self.recipient_team_id,
71+
recipient_user_id=recipient_user_id or self.recipient_user_id,
72+
thread_ts=thread_ts,
73+
**kwargs,
74+
)

0 commit comments

Comments
 (0)