From 3aa719802f042c16bcac86b5ad96de71a57116cc Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 06:00:08 +0000 Subject: [PATCH] Refactor: Skip Slack channels where bot is not a member I modified the Slack indexing process in `index_slack_messages` to skip any channel (public or private) where the bot's `is_member` status is false. Previously, the indexing process would only explicitly skip private channels where the bot was not a member. For public channels, it would attempt to fetch history, relying on a `not_in_channel` error during history fetching to implicitly skip. This change makes the skipping behavior explicit for all channel types based on the `is_member` flag retrieved from `conversations.list` API call. This aims to reduce unnecessary API calls to `conversations.history` for channels the bot hasn't been invited to, potentially speeding up the indexing process and avoiding hitting rate limits unnecessarily. The `is_member` flag is reliably provided by the `SlackHistory.get_all_channels` method. Logging messages have been updated to reflect this change. --- surfsense_backend/app/tasks/connectors_indexing_tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/surfsense_backend/app/tasks/connectors_indexing_tasks.py b/surfsense_backend/app/tasks/connectors_indexing_tasks.py index 6af36ada1..6dc6740f9 100644 --- a/surfsense_backend/app/tasks/connectors_indexing_tasks.py +++ b/surfsense_backend/app/tasks/connectors_indexing_tasks.py @@ -124,9 +124,9 @@ async def index_slack_messages( # If it's a private channel and the bot is not a member, skip. # For public channels, if they are listed by conversations.list, the bot can typically read history. # The `not_in_channel` error in get_conversation_history will be the ultimate gatekeeper if history is inaccessible. - if is_private and not is_member: - logger.warning(f"Bot is not a member of private channel {channel_name} ({channel_id}). Skipping.") - skipped_channels.append(f"{channel_name} (private, bot not a member)") + if not is_member: + logger.warning(f"Bot is not a member of channel {channel_name} ({channel_id}) (public or private). Skipping.") + skipped_channels.append(f"{channel_name} (bot not a member)") documents_skipped += 1 continue