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.
This commit is contained in:
google-labs-jules[bot] 2025-05-28 06:00:08 +00:00
parent fd6da4c472
commit 3aa719802f

View file

@ -124,9 +124,9 @@ async def index_slack_messages(
# If it's a private channel and the bot is not a member, skip. # 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. # 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. # 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: if not is_member:
logger.warning(f"Bot is not a member of private channel {channel_name} ({channel_id}). Skipping.") logger.warning(f"Bot is not a member of channel {channel_name} ({channel_id}) (public or private). Skipping.")
skipped_channels.append(f"{channel_name} (private, bot not a member)") skipped_channels.append(f"{channel_name} (bot not a member)")
documents_skipped += 1 documents_skipped += 1
continue continue