Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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,
)
30 changes: 30 additions & 0 deletions tests/slack_bolt/context/test_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def test_default_params(self):
"recipient_team_id": "T111",
"recipient_user_id": "U111",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I overlooked how these asserts are expecting internal arguments, if you find a better solution to please contribute it 🙏 We don't want this to become a pattern in the project 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might need to set up a mock web server and capture the request sent to it 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@WilliamBergamin I'll hold off on merging this to find these preferred patterns! Super appreciate the second thought toward this 🧠 💡

}

def test_parameter_overrides(self):
Expand All @@ -63,6 +66,9 @@ def test_parameter_overrides(self):
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": None,
}

def test_buffer_size_overrides(self):
Expand All @@ -88,4 +94,28 @@ def test_buffer_size_overrides(self):
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": 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",
)
stream = say_stream(icon_emoji=":maple_leaf:", username="Charlie Brown")

assert stream._stream_args == {
"channel": "C111",
"thread_ts": "111.222",
"recipient_team_id": "T111",
"recipient_user_id": "U111",
"task_display_mode": None,
"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
31 changes: 31 additions & 0 deletions tests/slack_bolt_async/context/test_async_say_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ async def test_default_params(self):
"recipient_team_id": "T111",
"recipient_user_id": "U111",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": None,
}

@pytest.mark.asyncio
Expand All @@ -75,6 +78,9 @@ async def test_parameter_overrides(self):
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": None,
}

@pytest.mark.asyncio
Expand All @@ -101,4 +107,29 @@ async def test_buffer_size_overrides(self):
"recipient_team_id": "T222",
"recipient_user_id": "U222",
"task_display_mode": None,
"icon_emoji": None,
"icon_url": None,
"username": None,
}

@pytest.mark.asyncio
async def test_authorship_overrides(self):
say_stream = AsyncSayStream(
client=self.web_client,
channel="C111",
recipient_team_id="T111",
recipient_user_id="U111",
thread_ts="111.222",
)
stream = await say_stream(icon_emoji=":maple_leaf:", username="Charlie Brown")

assert stream._stream_args == {
"channel": "C111",
"thread_ts": "111.222",
"recipient_team_id": "T111",
"recipient_user_id": "U111",
"task_display_mode": None,
"icon_emoji": ":maple_leaf:",
"icon_url": None,
"username": "Charlie Brown",
}
10 changes: 10 additions & 0 deletions tests/slack_bolt_async/context/test_async_set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ async def test_set_status_loading_messages(self):
)
assert response.status_code == 200

@pytest.mark.asyncio
async def test_set_status_authorship(self):
set_status = AsyncSetStatus(client=self.web_client, channel_id="C111", thread_ts="123.123")
response: AsyncSlackResponse = await set_status(
status="Thinking...",
icon_emoji=":maple_leaf:",
username="Charlie Brown",
)
assert response.status_code == 200

@pytest.mark.asyncio
async def test_set_status_invalid(self):
set_status = AsyncSetStatus(client=self.web_client, channel_id="C111", thread_ts="123.123")
Expand Down