Skip to content

feat: add app_mention event handler#14

Merged
mwbrooks merged 7 commits intoslack-samples:ai-appsfrom
srtaalej:feature/app-mention
Oct 1, 2025
Merged

feat: add app_mention event handler#14
mwbrooks merged 7 commits intoslack-samples:ai-appsfrom
srtaalej:feature/app-mention

Conversation

@srtaalej
Copy link
Copy Markdown
Contributor

@srtaalej srtaalej commented Sep 26, 2025

Type of change

  • New feature
  • Bug fix
  • Documentation

Summary

enable in-channel assistant streaming

Requirements

  • I have ensured the changes I am contributing align with existing patterns and have tested and linted my code
  • I've read and agree to the Code of Conduct

@srtaalej srtaalej requested review from mwbrooks and zimeg September 26, 2025 19:52
@srtaalej srtaalej self-assigned this Sep 26, 2025
@srtaalej srtaalej added the enhancement New feature or request label Sep 26, 2025
Copy link
Copy Markdown
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

Looking good @srtaalej! Left a question before I start testing the sample app changes 😄

Comment thread listeners/events/__init__.py Outdated
Comment on lines +21 to +24
# 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❓ Do we want to keep this commented out rather than deleted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

🗣️ Super quick thoughts but this is so good! About to test some edge cases and will follow up with findings!

Comment thread listeners/events/__init__.py Outdated
Comment on lines +21 to +24
# 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👁️‍🗨️ 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes i like this idea!

Comment thread listeners/events/assistant_mentioned.py Outdated
"""


def assistant_mentioned_callback(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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!

@srtaalej srtaalej requested review from mwbrooks and zimeg September 30, 2025 21:20
Copy link
Copy Markdown
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

✅ 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).

Copy link
Copy Markdown
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@srtaalej LGTM! Thanks so much for all of the feedback and enhancements once more. I think we should merge this soon and follow up with feedback and changes alike! 🚢 💨

Comment on lines +86 to +105
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}]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🪓 suggestion(non-blocking): I think later we should remove this in favor of a search method to showcase other AI focused features?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Super +1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⭐ praise: Thanks so much for removing this! I'm a fan of the unlock this brings for adjacent events.

Comment thread manifest.json
Comment on lines +40 to +42
"message.im",
"app_mention",
"message.channels"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🧮 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-

@mwbrooks mwbrooks merged commit ec9fb79 into slack-samples:ai-apps Oct 1, 2025
3 checks passed
@srtaalej srtaalej deleted the feature/app-mention branch October 1, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants