-
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
Draft
WilliamBergamin
wants to merge
10
commits into
main
Choose a base branch
from
update-set-suggested-prompts-init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+634
−132
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba87272
feat: make set_suggested_prompts accessible by all DMs to app
WilliamBergamin af21620
Improve things but still stuff to do
WilliamBergamin 3e7031b
bring assistant logic to general bolt logic
WilliamBergamin cbfbae6
chore: fix bug
WilliamBergamin 07d70ef
test: trim test_payload_utils to new-behavior tests only
WilliamBergamin 8da62af
Merge branch 'main' into update-set-suggested-prompts-init
WilliamBergamin 19fced4
refactor: scope set_title to assistant threads via AssistantUtilities
WilliamBergamin 8f33d65
chore: clean up pr
WilliamBergamin 25768ba
fis: improve based on code review
WilliamBergamin 812f7c3
feat: attach set_suggested_prompts on app_home_opened Messages tab
WilliamBergamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
||
| prompts=prompts_arg, | ||
| title=title, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍🏻