From 02fa11c8454662a5c168b491fa1220e51e9a4cbc Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Wed, 26 May 2021 18:30:29 +0300 Subject: [PATCH] Use cursor in Slack Alerts example --- examples/services/monitoring/slack_alerts.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/services/monitoring/slack_alerts.py b/examples/services/monitoring/slack_alerts.py index 731a0744..c0272625 100644 --- a/examples/services/monitoring/slack_alerts.py +++ b/examples/services/monitoring/slack_alerts.py @@ -69,8 +69,15 @@ class SlackMonitor(Monitor): self.slack_client.api_test() # Find channel ID - response = self.slack_client.conversations_list(limit=1000) - channel_id = [channel_info.get('id') for channel_info in response.data['channels'] + channels = [] + cursor = None + while True: + response = self.slack_client.conversations_list(cursor=cursor) + channels.extend(response.data['channels']) + cursor = response.data["response_metadata"].get("next_cursor") + if not cursor: + break + channel_id = [channel_info.get('id') for channel_info in channels if channel_info.get('name') == self.channel] if not channel_id: raise ValueError('Error: Could not locate channel name \'{}\''.format(self.channel))