-
Notifications
You must be signed in to change notification settings - Fork 288
feat: widen set_suggested_prompts initialization scope to any DM #1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ba87272
af21620
3e7031b
cbfbae6
07d70ef
8da62af
19fced4
8f33d65
25768ba
812f7c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,13 @@ | |
| class SetSuggestedPrompts: | ||
| client: WebClient | ||
| channel_id: str | ||
| thread_ts: str | ||
| thread_ts: Optional[str] | ||
|
|
||
| def __init__( | ||
| self, | ||
| client: WebClient, | ||
| channel_id: str, | ||
| thread_ts: str, | ||
| thread_ts: Optional[str] = None, | ||
| ): | ||
| self.client = client | ||
| self.channel_id = channel_id | ||
|
|
@@ -23,6 +23,7 @@ def __call__( | |
| self, | ||
| prompts: Sequence[Union[str, Dict[str, str]]], | ||
| title: Optional[str] = None, | ||
| thread_ts: Optional[str] = None, | ||
| ) -> SlackResponse: | ||
| prompts_arg: List[Dict[str, str]] = [] | ||
| for prompt in prompts: | ||
|
|
@@ -33,7 +34,7 @@ def __call__( | |
|
|
||
| return self.client.assistant_threads_setSuggestedPrompts( | ||
| channel_id=self.channel_id, | ||
| thread_ts=self.thread_ts, | ||
| thread_ts=thread_ts if thread_ts is not None else self.thread_ts, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(mypy): I'm finding that mypy is failing here (and on the async-version):
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting 👀 what version of python are you using to run The mypy typechecking in CI seems to be passing 🟢 and its working on my machine 😅
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange, I'm going to assume this is a user (michael) error @WilliamBergamin 😅 Python version: $ python --version
Python 3.12.11mypy failures with: $ ./scripts/run_mypy.sh --no-install
slack_bolt/context/set_suggested_prompts/set_suggested_prompts.py:37: error: Argument "thread_ts" to "assistant_threads_setSuggestedPrompts" of "WebClient" has incompatible type "Optional[str]"; expected "str" [arg-type]
slack_bolt/context/ack/async_ack.py:15: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
slack_bolt/context/ack/ack.py:15: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
slack_bolt/context/set_suggested_prompts/async_set_suggested_prompts.py:37: error: Argument "thread_ts" to "assistant_threads_setSuggestedPrompts" of "AsyncWebClient" has incompatible type "Optional[str]"; expected "str" [arg-type]❓ Should I be running Python 3.14 even though we test against lower version of Python? |
||
| prompts=prompts_arg, | ||
| title=title, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,17 @@ | |
| from slack_bolt.context.assistant.thread_context_store.async_store import AsyncAssistantThreadContextStore | ||
| from slack_bolt.context.say_stream.async_say_stream import AsyncSayStream | ||
| from slack_bolt.context.set_status.async_set_status import AsyncSetStatus | ||
| from slack_bolt.context.set_suggested_prompts.async_set_suggested_prompts import AsyncSetSuggestedPrompts | ||
| from slack_bolt.middleware.async_middleware import AsyncMiddleware | ||
| from slack_bolt.request.async_request import AsyncBoltRequest | ||
| from slack_bolt.request.payload_utils import is_assistant_event, to_event | ||
| from slack_bolt.request.payload_utils import ( | ||
| is_app_home_opened_event, | ||
| is_assistant_event, | ||
| is_assistant_thread_context_changed_event, | ||
| is_assistant_thread_started_event, | ||
| is_im_message_event, | ||
| to_event, | ||
| ) | ||
| from slack_bolt.response import BoltResponse | ||
|
|
||
|
|
||
|
|
@@ -25,32 +33,48 @@ async def async_process( | |
| next: Callable[[], Awaitable[BoltResponse]], | ||
| ) -> Optional[BoltResponse]: | ||
| event = to_event(req.body) | ||
| if event is not None: | ||
| if is_assistant_event(req.body): | ||
| assistant = AsyncAssistantUtilities( | ||
| payload=event, | ||
| context=req.context, | ||
| thread_context_store=self.thread_context_store, | ||
| ) | ||
| req.context["say"] = assistant.say | ||
| req.context["set_title"] = assistant.set_title | ||
| req.context["set_suggested_prompts"] = assistant.set_suggested_prompts | ||
| req.context["get_thread_context"] = assistant.get_thread_context | ||
| req.context["save_thread_context"] = assistant.save_thread_context | ||
|
|
||
| # TODO: in the future we might want to introduce a "proper" extract_ts utility | ||
| thread_ts = req.context.thread_ts or event.get("ts") | ||
| if req.context.channel_id and thread_ts: | ||
| req.context["set_status"] = AsyncSetStatus( | ||
| client=req.context.client, | ||
| channel_id=req.context.channel_id, | ||
| thread_ts=thread_ts, | ||
| ) | ||
| req.context["say_stream"] = AsyncSayStream( | ||
| client=req.context.client, | ||
| channel=req.context.channel_id, | ||
| recipient_team_id=req.context.team_id or req.context.enterprise_id, | ||
| recipient_user_id=req.context.user_id, | ||
| thread_ts=thread_ts, | ||
| ) | ||
| if event is None: | ||
| return await next() | ||
| if req.context.channel_id is None: | ||
| return await next() | ||
|
|
||
| if is_assistant_event(req.body): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Nice |
||
| # TODO: eventually we might remove this assistant specific logic | ||
| assistant = AsyncAssistantUtilities( | ||
| payload=event, | ||
| context=req.context, | ||
| thread_context_store=self.thread_context_store, | ||
| ) | ||
| req.context["say"] = assistant.say | ||
| req.context["set_title"] = assistant.set_title | ||
| req.context["get_thread_context"] = assistant.get_thread_context | ||
| req.context["save_thread_context"] = assistant.save_thread_context | ||
|
|
||
| if ( | ||
| is_im_message_event(req.body) | ||
| or is_assistant_thread_started_event(req.body) | ||
| or is_assistant_thread_context_changed_event(req.body) | ||
| or is_app_home_opened_event(req.body, tab="messages") | ||
| ): | ||
| req.context["set_suggested_prompts"] = AsyncSetSuggestedPrompts( | ||
| client=req.context.client, | ||
| channel_id=req.context.channel_id, | ||
| thread_ts=req.context.thread_ts, | ||
| ) | ||
|
|
||
| # TODO: in the future we might want to introduce a "proper" extract_ts utility | ||
| thread_ts_or_ts = req.context.thread_ts or event.get("ts") | ||
| if thread_ts_or_ts: | ||
| req.context["set_status"] = AsyncSetStatus( | ||
| client=req.context.client, | ||
| channel_id=req.context.channel_id, | ||
| thread_ts=thread_ts_or_ts, | ||
| ) | ||
| req.context["say_stream"] = AsyncSayStream( | ||
| client=req.context.client, | ||
| channel=req.context.channel_id, | ||
| recipient_team_id=req.context.team_id or req.context.enterprise_id, | ||
| recipient_user_id=req.context.user_id, | ||
| thread_ts=thread_ts_or_ts, | ||
| ) | ||
| return await next() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻