Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions slack_bolt/context/say_stream/async_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ async def __call__(
recipient_team_id: Optional[str] = None,
recipient_user_id: Optional[str] = None,
thread_ts: Optional[str] = None,
icon_emoji: Optional[str] = None,
icon_url: Optional[str] = None,
username: Optional[str] = None,
**kwargs,
) -> AsyncChatStream:
"""Starts a new chat stream with context."""
Expand All @@ -51,12 +54,18 @@ async def __call__(
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
thread_ts=thread_ts,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
return await self.client.chat_stream(
channel=channel,
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
thread_ts=thread_ts,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
9 changes: 9 additions & 0 deletions slack_bolt/context/say_stream/say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __call__(
recipient_team_id: Optional[str] = None,
recipient_user_id: Optional[str] = None,
thread_ts: Optional[str] = None,
icon_emoji: Optional[str] = None,
icon_url: Optional[str] = None,
username: Optional[str] = None,
**kwargs,
) -> ChatStream:
"""Starts a new chat stream with context."""
Expand All @@ -51,12 +54,18 @@ def __call__(
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
thread_ts=thread_ts,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
return self.client.chat_stream(
channel=channel,
recipient_team_id=recipient_team_id or self.recipient_team_id,
recipient_user_id=recipient_user_id or self.recipient_user_id,
thread_ts=thread_ts,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
6 changes: 6 additions & 0 deletions slack_bolt/context/set_status/async_set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ async def __call__(
self,
status: str,
loading_messages: Optional[List[str]] = None,
icon_emoji: Optional[str] = None,
icon_url: Optional[str] = None,
username: Optional[str] = None,
**kwargs,
) -> AsyncSlackResponse:
return await self.client.assistant_threads_setStatus(
channel_id=self.channel_id,
thread_ts=self.thread_ts,
status=status,
loading_messages=loading_messages,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
6 changes: 6 additions & 0 deletions slack_bolt/context/set_status/set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ def __call__(
self,
status: str,
loading_messages: Optional[List[str]] = None,
icon_emoji: Optional[str] = None,
icon_url: Optional[str] = None,
username: Optional[str] = None,
**kwargs,
) -> SlackResponse:
return self.client.assistant_threads_setStatus(
channel_id=self.channel_id,
thread_ts=self.thread_ts,
status=status,
loading_messages=loading_messages,
icon_emoji=icon_emoji,
icon_url=icon_url,
username=username,
**kwargs,
)
107 changes: 62 additions & 45 deletions tests/slack_bolt/context/test_say_stream.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import pytest
from unittest.mock import patch, MagicMock

from slack_sdk import WebClient

from slack_bolt.context.say_stream.say_stream import SayStream
from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server


class TestSayStream:
default_chat_stream_buffer_size = WebClient.chat_stream.__kwdefaults__["buffer_size"]

def setup_method(self):
setup_mock_web_api_server(self)
valid_token = "xoxb-valid"
mock_api_server_base_url = "http://localhost:8888"
self.web_client = WebClient(token=valid_token, base_url=mock_api_server_base_url)

def teardown_method(self):
cleanup_mock_web_api_server(self)
self.web_client = WebClient(token="xoxb-valid")

def test_missing_channel_raises(self):
say_stream = SayStream(client=self.web_client, channel=None, thread_ts="111.222")
Expand All @@ -35,16 +28,17 @@ def test_default_params(self):
recipient_user_id="U111",
thread_ts="111.222",
)
stream = say_stream()

assert stream._buffer_size == self.default_chat_stream_buffer_size
assert stream._stream_args == {
"channel": "C111",
"thread_ts": "111.222",
"recipient_team_id": "T111",
"recipient_user_id": "U111",
"task_display_mode": None,
}
with patch.object(self.web_client, "chat_stream", return_value=MagicMock()) as mock_chat_stream:
say_stream()
mock_chat_stream.assert_called_once_with(
channel="C111",
recipient_team_id="T111",
recipient_user_id="U111",
thread_ts="111.222",
icon_emoji=None,
icon_url=None,
username=None,
)

def test_parameter_overrides(self):
say_stream = SayStream(
Expand All @@ -54,16 +48,17 @@ def test_parameter_overrides(self):
recipient_user_id="U111",
thread_ts="111.222",
)
stream = say_stream(channel="C222", thread_ts="333.444", recipient_team_id="T222", recipient_user_id="U222")

assert stream._buffer_size == self.default_chat_stream_buffer_size
assert stream._stream_args == {
"channel": "C222",
"thread_ts": "333.444",
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
}
with patch.object(self.web_client, "chat_stream", return_value=MagicMock()) as mock_chat_stream:
say_stream(channel="C222", thread_ts="333.444", recipient_team_id="T222", recipient_user_id="U222")
mock_chat_stream.assert_called_once_with(
channel="C222",
recipient_team_id="T222",
recipient_user_id="U222",
thread_ts="333.444",
icon_emoji=None,
icon_url=None,
username=None,
)

def test_buffer_size_overrides(self):
say_stream = SayStream(
Expand All @@ -73,19 +68,41 @@ def test_buffer_size_overrides(self):
recipient_user_id="U111",
thread_ts="111.222",
)
stream = say_stream(
buffer_size=100,
channel="C222",
thread_ts="333.444",
recipient_team_id="T222",
recipient_user_id="U222",
)
with patch.object(self.web_client, "chat_stream", return_value=MagicMock()) as mock_chat_stream:
say_stream(
buffer_size=100,
channel="C222",
thread_ts="333.444",
recipient_team_id="T222",
recipient_user_id="U222",
)
mock_chat_stream.assert_called_once_with(
buffer_size=100,
channel="C222",
recipient_team_id="T222",
recipient_user_id="U222",
thread_ts="333.444",
icon_emoji=None,
icon_url=None,
username=None,
)

assert stream._buffer_size == 100
assert stream._stream_args == {
"channel": "C222",
"thread_ts": "333.444",
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
}
def test_authorship_overrides(self):
say_stream = SayStream(
client=self.web_client,
channel="C111",
recipient_team_id="T111",
recipient_user_id="U111",
thread_ts="111.222",
)
with patch.object(self.web_client, "chat_stream", return_value=MagicMock()) as mock_chat_stream:
say_stream(icon_emoji=":maple_leaf:", username="Charlie Brown")
mock_chat_stream.assert_called_once_with(
channel="C111",
recipient_team_id="T111",
recipient_user_id="U111",
thread_ts="111.222",
icon_emoji=":maple_leaf:",
icon_url=None,
username="Charlie Brown",
)
9 changes: 9 additions & 0 deletions tests/slack_bolt/context/test_set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def test_set_status_loading_messages(self):
)
assert response.status_code == 200

def test_set_status_authorship(self):
set_status = SetStatus(client=self.web_client, channel_id="C111", thread_ts="123.123")
response: SlackResponse = set_status(
status="Thinking...",
icon_emoji=":maple_leaf:",
username="Charlie Brown",
)
assert response.status_code == 200

def test_set_status_invalid(self):
set_status = SetStatus(client=self.web_client, channel_id="C111", thread_ts="123.123")
with pytest.raises(TypeError):
Expand Down
Loading