feat: add app_mention event handler#14
Conversation
| # app.event("assistant_thread_started")(start_thread_with_suggested_prompts) | ||
| # app.event("assistant_thread_context_changed")(save_new_thread_context) | ||
| # app.event("message", matchers=[is_user_message_event_in_assistant_thread])(respond_to_user_message) | ||
| # app.event("message", matchers=[is_message_event_in_assistant_thread])(just_ack) |
There was a problem hiding this comment.
❓ Do we want to keep this commented out rather than deleted?
There was a problem hiding this comment.
i left it commented out so that listeners/event could stay somewhat of an example folder. i can see how it might be confusing to have all of these comments in there though
zimeg
left a comment
There was a problem hiding this comment.
🗣️ Super quick thoughts but this is so good! About to test some edge cases and will follow up with findings!
| # app.event("assistant_thread_started")(start_thread_with_suggested_prompts) | ||
| # app.event("assistant_thread_context_changed")(save_new_thread_context) | ||
| # app.event("message", matchers=[is_user_message_event_in_assistant_thread])(respond_to_user_message) | ||
| # app.event("message", matchers=[is_message_event_in_assistant_thread])(just_ack) |
There was a problem hiding this comment.
👁️🗨️ thought: I'm wondering if we want to move the explicit event listener implementation to the Bolt Python upstream examples instead of commenting this out here?
🔍 ramble: We have a few related examples at this time and I think these listeners might find a nice event_app.py file or similar. Super curious if you think this makes sense for this template?
There was a problem hiding this comment.
yes i like this idea!
| """ | ||
|
|
||
|
|
||
| def assistant_mentioned_callback( |
There was a problem hiding this comment.
| def assistant_mentioned_callback( | |
| def app_mentioned_callback( |
🤖 quibble: Matching the event might make this clear in lookups without limiting this to an "assistant" paradigm!
mwbrooks
left a comment
There was a problem hiding this comment.
✅ I've pushed a few commits to update the app_mention event handling. Things are looking good on my side but I'll let @zimeg do a final review.
🧪 Tested locally. Tested both the Assistant thread experience, in-channel messages, and DM experience (there is a bug in the DM, but it's unrelated to this PR).
| if user_message == "Can you generate a brief summary of the referred channel?": | ||
| # the logic here requires the additional bot scopes: | ||
| # channels:join, channels:history, groups:history | ||
| thread_context = get_thread_context() | ||
| referred_channel_id = thread_context.get("channel_id") | ||
| try: | ||
| channel_history = client.conversations_history(channel=referred_channel_id, limit=50) | ||
| except SlackApiError as e: | ||
| if e.response["error"] == "not_in_channel": | ||
| # If this app's bot user is not in the public channel, | ||
| # we'll try joining the channel and then calling the same API again | ||
| client.conversations_join(channel=referred_channel_id) | ||
| channel_history = client.conversations_history(channel=referred_channel_id, limit=50) | ||
| else: | ||
| raise e | ||
| prompt = f"Can you generate a brief summary of these messages in a Slack channel <#{referred_channel_id}>?\n\n" | ||
| for message in reversed(channel_history.get("messages")): | ||
| if message.get("user") is not None: | ||
| prompt += f"\n<@{message['user']}> says: {message['text']}\n" | ||
| messages_in_thread = [{"role": "user", "content": prompt}] |
There was a problem hiding this comment.
🪓 suggestion(non-blocking): I think later we should remove this in favor of a search method to showcase other AI focused features?
There was a problem hiding this comment.
⭐ praise: Thanks so much for removing this! I'm a fan of the unlock this brings for adjacent events.
| "message.im", | ||
| "app_mention", | ||
| "message.channels" |
There was a problem hiding this comment.
🧮 quibble: Hm perhaps in follow ups we revist the scopes and ordering here? I believe this makes inspecting the app a bit more simple at first glance-
Type of change
Summary
enable in-channel assistant streaming
Requirements