From 7e9b12403a7a95a095d5a06c457b7e0d4771b545 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 17:29:23 -0800 Subject: [PATCH] Allow Slack workflow messages when respond_to_bots is enabled (#3819) * Allow workflow 'bot_message' subtype when respond_to_bots is enabled Co-Authored-By: Chris Weaver * refactor: consolidate bot message checks to avoid redundant code Co-Authored-By: Chris Weaver * style: fix black formatting Co-Authored-By: Chris Weaver * Remove unnecessary call --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Chris Weaver Co-authored-by: Weves --- backend/onyx/onyxbot/slack/listener.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/onyx/onyxbot/slack/listener.py b/backend/onyx/onyxbot/slack/listener.py index 106891d419e..721140fa11e 100644 --- a/backend/onyx/onyxbot/slack/listener.py +++ b/backend/onyx/onyxbot/slack/listener.py @@ -537,30 +537,36 @@ def prefilter_requests(req: SocketModeRequest, client: TenantSocketModeClient) - # Let the tag flow handle this case, don't reply twice return False - if event.get("bot_profile"): + # Check if this is a bot message (either via bot_profile or bot_message subtype) + is_bot_message = bool( + event.get("bot_profile") or event.get("subtype") == "bot_message" + ) + if is_bot_message: channel_name, _ = get_channel_name_from_id( client=client.web_client, channel_id=channel ) - with get_session_with_tenant(client.tenant_id) as db_session: slack_channel_config = get_slack_channel_config_for_bot_and_channel( db_session=db_session, slack_bot_id=client.slack_bot_id, channel_name=channel_name, ) + # If OnyxBot is not specifically tagged and the channel is not set to respond to bots, ignore the message if (not bot_tag_id or bot_tag_id not in msg) and ( not slack_channel_config or not slack_channel_config.channel_config.get("respond_to_bots") ): - channel_specific_logger.info("Ignoring message from bot") + channel_specific_logger.info( + "Ignoring message from bot since respond_to_bots is disabled" + ) return False # Ignore things like channel_join, channel_leave, etc. # NOTE: "file_share" is just a message with a file attachment, so we # should not ignore it message_subtype = event.get("subtype") - if message_subtype not in [None, "file_share"]: + if message_subtype not in [None, "file_share", "bot_message"]: channel_specific_logger.info( f"Ignoring message with subtype '{message_subtype}' since it is a special message type" )