Skip to content

Commit

Permalink
Added support to allow only public slack channels
Browse files Browse the repository at this point in the history
  • Loading branch information
shresakamai committed Dec 31, 2024
1 parent 965aa04 commit c8d5051
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,12 @@ def _is_regex(self, pattern: str) -> bool:
except re.error:
return False

def _list_channels(self) -> List[Dict[str, Any]]:
"""List all channels (public and private)."""
def _list_channels(self, types: str) -> List[Dict[str, Any]]:
"""List channels based on the types."""
from slack_sdk.errors import SlackApiError

try:
result = self._client.conversations_list(
types="public_channel,private_channel"
)
result = self._client.conversations_list(types=types)
return result["channels"]
except SlackApiError as e:
logger.error(f"Error fetching channels: {e.response['error']}")
Expand All @@ -275,7 +273,9 @@ def _filter_channels(
filtered_channels.append(channel)
return filtered_channels

def get_channel_ids(self, channel_patterns: List[str]) -> List[str]:
def get_channel_ids(
self, channel_patterns: List[str], types: str = "public_channel,private_channel"
) -> List[str]:
"""Get list of channel IDs based on names and regex patterns.
Args:
Expand All @@ -287,7 +287,7 @@ def get_channel_ids(self, channel_patterns: List[str]) -> List[str]:
if not channel_patterns:
raise ValueError("No channel patterns provided.")

channels = self._list_channels()
channels = self._list_channels(types)
logger.info(f"Total channels fetched: {len(channels)}")

if not channels:
Expand Down

0 comments on commit c8d5051

Please sign in to comment.