Skip to content
Merged
Prev Previous commit
Next Next commit
Improve conssistancy in naming
  • Loading branch information
WilliamBergamin committed Mar 18, 2026
commit 42b6c4d217e7a3c75168fd1062dd7af72effb777
24 changes: 12 additions & 12 deletions slack_bolt/context/say_stream/async_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@

class AsyncSayStream:
client: AsyncWebClient
channel_id: Optional[str]
channel: Optional[str]
thread_ts: Optional[str]
team_id: Optional[str]
user_id: Optional[str]
recipient_team_id: Optional[str]
recipient_user_id: Optional[str]

def __init__(
self,
*,
client: AsyncWebClient,
channel_id: Optional[str] = None,
channel: Optional[str] = None,
thread_ts: Optional[str] = None,
team_id: Optional[str] = None,
user_id: Optional[str] = None,
recipient_team_id: Optional[str] = None,
recipient_user_id: Optional[str] = None,
):
self.client = client
self.channel_id = channel_id
self.channel = channel
self.thread_ts = thread_ts
self.team_id = team_id
self.user_id = user_id
self.recipient_team_id = recipient_team_id
self.recipient_user_id = recipient_user_id

async def __call__(
self,
Expand All @@ -44,7 +44,7 @@ async def __call__(
stacklevel=2,
)

channel = channel or self.channel_id
channel = channel or self.channel
thread_ts = thread_ts or self.thread_ts
if channel is None:
raise ValueError("say_stream without channel here is unsupported")
Expand All @@ -54,7 +54,7 @@ async def __call__(
return await self.client.chat_stream(
channel=channel,
thread_ts=thread_ts,
recipient_team_id=recipient_team_id or self.team_id,
recipient_user_id=recipient_user_id or self.user_id,
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
**kwargs,
)
24 changes: 12 additions & 12 deletions slack_bolt/context/say_stream/say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@

class SayStream:
client: WebClient
channel_id: Optional[str]
channel: Optional[str]
thread_ts: Optional[str]
team_id: Optional[str]
user_id: Optional[str]
recipient_team_id: Optional[str]
recipient_user_id: Optional[str]

def __init__(
self,
*,
client: WebClient,
channel_id: Optional[str] = None,
channel: Optional[str] = None,
thread_ts: Optional[str] = None,
team_id: Optional[str] = None,
user_id: Optional[str] = None,
recipient_team_id: Optional[str] = None,
recipient_user_id: Optional[str] = None,
):
self.client = client
self.channel_id = channel_id
self.channel = channel
self.thread_ts = thread_ts
self.team_id = team_id
self.user_id = user_id
self.recipient_team_id = recipient_team_id
self.recipient_user_id = recipient_user_id

def __call__(
self,
Expand All @@ -44,7 +44,7 @@ def __call__(
stacklevel=2,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 note: I might not find this in outputs at the moment - would this be something to include in docstring for say_stream too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not find this in outputs at the moment

Interesting 🤔 I an seeing it on my end, let me see how I should add this to the docstring

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-03-19 at 9 50 58 AM

Warning added to docstring


channel = channel or self.channel_id
channel = channel or self.channel
thread_ts = thread_ts or self.thread_ts
if channel is None:
raise ValueError("say_stream without channel here is unsupported")
Expand All @@ -54,7 +54,7 @@ def __call__(
return self.client.chat_stream(
channel=channel,
thread_ts=thread_ts,
recipient_team_id=recipient_team_id or self.team_id,
recipient_user_id=recipient_user_id or self.user_id,
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
**kwargs,
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ async def async_process(
if req.context.channel_id and thread_ts:
req.context["say_stream"] = AsyncSayStream(
client=req.context.client,
channel_id=req.context.channel_id,
channel=req.context.channel_id,
thread_ts=thread_ts,
team_id=req.context.team_id,
user_id=req.context.user_id,
recipient_team_id=req.context.team_id,
recipient_user_id=req.context.user_id,
)
return await next()
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def process(self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], Bo
if req.context.channel_id and thread_ts:
req.context["say_stream"] = SayStream(
client=req.context.client,
channel_id=req.context.channel_id,
channel=req.context.channel_id,
thread_ts=thread_ts,
team_id=req.context.team_id,
user_id=req.context.user_id,
recipient_team_id=req.context.team_id,
recipient_user_id=req.context.user_id,
)
Comment on lines +35 to +44

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👾 thought: Defaulting to different threading behavior for say and say_stream concerns me somewhat.

🔮 ramble: I understand thread_ts is required to stream chat at this time, but if "parent" messages can be streamed in the future we might want to revisit also say behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yess I think we can revisite the say behavior in the future, but changing it I think would result a breaking change 🤔

I can add a TODO or maybe create an issue for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamBergamin Thanks for keeping note of this too! 📫

I'm partial to waiting for related feedback since this might be an expected experience for most! I fear that knowing some of the implementation details biases me...

return next()
22 changes: 12 additions & 10 deletions tests/scenario_tests/test_events_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def test_say_stream_injected_for_app_mention(self):
def handle_mention(say_stream: SayStream, context: BoltContext):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "C111"
assert say_stream == context.say_stream
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1595926230.009600"
assert say_stream.team_id == context.team_id
assert say_stream.user_id == context.user_id
assert say_stream.recipient_team_id == context.team_id
assert say_stream.recipient_user_id == context.user_id
called["value"] = True

request = BoltRequest(body=app_mention_event_body, mode="socket_mode")
Expand All @@ -73,10 +74,11 @@ def test_say_stream_injected_for_threaded_message(self):
def handle_message(say_stream: SayStream, context: BoltContext):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "D111"
assert say_stream == context.say_stream
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
assert say_stream.team_id == context.team_id
assert say_stream.user_id == context.user_id
assert say_stream.recipient_team_id == context.team_id
assert say_stream.recipient_user_id == context.user_id
called["value"] = True

request = BoltRequest(body=threaded_user_message_event_body, mode="socket_mode")
Expand All @@ -92,7 +94,7 @@ def test_say_stream_in_user_message(self):
def handle_user_message(say_stream: SayStream):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "C111"
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1610261659.001400"
called["value"] = True

Expand All @@ -109,7 +111,7 @@ def test_say_stream_in_bot_message(self):
def handle_bot_message(say_stream: SayStream):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "C111"
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1610261539.000900"
called["value"] = True

Expand Down Expand Up @@ -142,7 +144,7 @@ def test_say_stream_in_assistant_thread_started(self):
def start_thread(say_stream: SayStream):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "D111"
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
called["value"] = True
Comment thread
WilliamBergamin marked this conversation as resolved.

Expand All @@ -162,7 +164,7 @@ def test_say_stream_in_assistant_user_message(self):
def handle_user_message(say_stream: SayStream):
assert say_stream is not None
assert isinstance(say_stream, SayStream)
assert say_stream.channel_id == "D111"
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
called["value"] = True

Expand Down
22 changes: 12 additions & 10 deletions tests/scenario_tests_async/test_events_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ async def test_say_stream_injected_for_app_mention(self):
async def handle_mention(say_stream: AsyncSayStream, context: AsyncBoltContext):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "C111"
assert say_stream == context.say_stream
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1595926230.009600"
assert say_stream.team_id == context.team_id
assert say_stream.user_id == context.user_id
assert say_stream.recipient_team_id == context.team_id
assert say_stream.recipient_user_id == context.user_id
called["value"] = True

request = AsyncBoltRequest(body=app_mention_event_body, mode="socket_mode")
Expand All @@ -78,10 +79,11 @@ async def test_say_stream_injected_for_threaded_message(self):
async def handle_message(say_stream: AsyncSayStream, context: AsyncBoltContext):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "D111"
assert say_stream == context.say_stream
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
assert say_stream.team_id == context.team_id
assert say_stream.user_id == context.user_id
assert say_stream.recipient_team_id == context.team_id
assert say_stream.recipient_user_id == context.user_id
called["value"] = True

request = AsyncBoltRequest(body=threaded_user_message_event_body, mode="socket_mode")
Expand All @@ -98,7 +100,7 @@ async def test_say_stream_in_user_message(self):
async def handle_user_message(say_stream: AsyncSayStream):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "C111"
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1610261659.001400"
called["value"] = True

Expand All @@ -116,7 +118,7 @@ async def test_say_stream_in_bot_message(self):
async def handle_user_message(say_stream: AsyncSayStream):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "C111"
assert say_stream.channel == "C111"
assert say_stream.thread_ts == "1610261539.000900"
called["value"] = True

Expand Down Expand Up @@ -151,7 +153,7 @@ async def test_say_stream_in_assistant_thread_started(self):
async def start_thread(say_stream: AsyncSayStream, context: AsyncBoltContext):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "D111"
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
called["value"] = True

Expand All @@ -172,7 +174,7 @@ async def test_say_stream_in_assistant_user_message(self):
async def handle_user_message(say_stream: AsyncSayStream, context: AsyncBoltContext):
assert say_stream is not None
assert isinstance(say_stream, AsyncSayStream)
assert say_stream.channel_id == "D111"
assert say_stream.channel == "D111"
assert say_stream.thread_ts == "1726133698.626339"
called["value"] = True

Expand Down
20 changes: 10 additions & 10 deletions tests/slack_bolt/context/test_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ def teardown_method(self):
cleanup_mock_web_api_server(self)

def test_missing_channel_raises(self):
say_stream = SayStream(client=self.web_client, channel_id=None, thread_ts="111.222")
say_stream = SayStream(client=self.web_client, channel=None, thread_ts="111.222")
with pytest.warns(ExperimentalWarning):
with pytest.raises(ValueError, match="channel"):
say_stream()

def test_missing_thread_ts_raises(self):
say_stream = SayStream(client=self.web_client, channel_id="C111", thread_ts=None)
say_stream = SayStream(client=self.web_client, channel="C111", thread_ts=None)
with pytest.warns(ExperimentalWarning):
with pytest.raises(ValueError, match="thread_ts"):
say_stream()

def test_default_params(self):
say_stream = SayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
team_id="T111",
user_id="U111",
recipient_team_id="T111",
recipient_user_id="U111",
)
stream = say_stream()

Expand All @@ -49,10 +49,10 @@ def test_default_params(self):
def test_parameter_overrides(self):
say_stream = SayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
team_id="T111",
user_id="U111",
recipient_team_id="T111",
recipient_user_id="U111",
)
stream = say_stream(channel="C222", thread_ts="333.444", recipient_team_id="T222", recipient_user_id="U222")

Expand All @@ -67,7 +67,7 @@ def test_parameter_overrides(self):
def test_buffer_size_passthrough(self):
say_stream = SayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
)
stream = say_stream(buffer_size=100)
Expand All @@ -77,7 +77,7 @@ def test_buffer_size_passthrough(self):
def test_experimental_warning(self):
say_stream = SayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
)
with pytest.warns(ExperimentalWarning, match="say_stream is experimental"):
Expand Down
20 changes: 10 additions & 10 deletions tests/slack_bolt_async/context/test_async_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def setup_teardown(self):

@pytest.mark.asyncio
async def test_missing_channel_raises(self):
say_stream = AsyncSayStream(client=self.web_client, channel_id=None, thread_ts="111.222")
say_stream = AsyncSayStream(client=self.web_client, channel=None, thread_ts="111.222")
with pytest.warns(ExperimentalWarning):
with pytest.raises(ValueError, match="channel"):
await say_stream()

@pytest.mark.asyncio
async def test_missing_thread_ts_raises(self):
say_stream = AsyncSayStream(client=self.web_client, channel_id="C111", thread_ts=None)
say_stream = AsyncSayStream(client=self.web_client, channel="C111", thread_ts=None)
with pytest.warns(ExperimentalWarning):
with pytest.raises(ValueError, match="thread_ts"):
await say_stream()
Expand All @@ -42,10 +42,10 @@ async def test_missing_thread_ts_raises(self):
async def test_default_params(self):
say_stream = AsyncSayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
team_id="T111",
user_id="U111",
recipient_team_id="T111",
recipient_user_id="U111",
)
stream = await say_stream()
assert stream._stream_args == {
Expand All @@ -60,10 +60,10 @@ async def test_default_params(self):
async def test_parameter_overrides(self):
say_stream = AsyncSayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
team_id="T111",
user_id="U111",
recipient_team_id="T111",
recipient_user_id="U111",
)
stream = await say_stream(channel="C222", thread_ts="333.444", recipient_team_id="T222", recipient_user_id="U222")

Expand All @@ -79,7 +79,7 @@ async def test_parameter_overrides(self):
async def test_buffer_size_passthrough(self):
say_stream = AsyncSayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
)
stream = await say_stream(buffer_size=100)
Expand All @@ -90,7 +90,7 @@ async def test_buffer_size_passthrough(self):
async def test_experimental_warning(self):
say_stream = AsyncSayStream(
client=self.web_client,
channel_id="C111",
channel="C111",
thread_ts="111.222",
)
with pytest.warns(ExperimentalWarning, match="say_stream is experimental"):
Expand Down
Loading