@@ -22,7 +22,7 @@ def connect_slack(args, token):
2222 system .print_error (args , f"Failed to connect to Slack with error: { e .response ['error' ]} " )
2323 return None
2424
25- def check_slack_messages (args , client , patterns , profile_name , channel_types , isExternal , read_from , channel_ids = None , limit_mins = 60 , archived_channels = False ):
25+ def check_slack_messages (args , client , patterns , profile_name , channel_types , isExternal , read_from , channel_ids = None , limit_mins = 60 , archived_channels = False , onlyArchived = False ):
2626 results = []
2727 try :
2828 connection = system .get_connection (args )
@@ -59,6 +59,8 @@ def rate_limit_retry(func, *args, **kwargs):
5959 cursor = None
6060 while True :
6161 try :
62+ if onlyArchived :
63+ archived_channels = True
6264 if archived_channels :
6365 system .print_debug (args , f"Considering archived channels, you may want to set archived_channels to False" )
6466 else :
@@ -71,7 +73,11 @@ def rate_limit_retry(func, *args, **kwargs):
7173 cursor = cursor ,
7274 exclude_archived = not archived_channels
7375 )
74- channels .extend (response .get ("channels" , []))
76+ if onlyArchived :
77+ system .print_info (args , "Getting only archived channels...." )
78+ channels .extend ([channel for channel in response .get ("channels" , []) if channel .get ("is_archived" )])
79+ else :
80+ channels .extend (response .get ("channels" , []))
7581 # Update the cursor for the next batch
7682 cursor = response .get ("response_metadata" , {}).get ("next_cursor" )
7783
@@ -355,8 +361,9 @@ def execute(args):
355361 channel_ids = config .get ('channel_ids' , [])
356362 limit_mins = config .get ('limit_mins' , 60 )
357363 isExternal = config .get ('isExternal' , None )
364+ onlyArchived = config .get ('onlyArchived' , False )
358365 archived_channels = config .get ('archived_channels' , False )
359-
366+
360367 if token :
361368 system .print_info (args , f"Checking Slack Profile { key } " )
362369 else :
@@ -365,7 +372,7 @@ def execute(args):
365372
366373 client = connect_slack (args , token )
367374 if client :
368- results += check_slack_messages (args , client , patterns , key , channel_types , isExternal , read_from , channel_ids , limit_mins , archived_channels )
375+ results += check_slack_messages (args , client , patterns , key , channel_types , isExternal , read_from , channel_ids , limit_mins , archived_channels , onlyArchived )
369376 else :
370377 system .print_error (args , "No Slack connection details found in connection.yml" )
371378 else :
0 commit comments