Use cursor in Slack Alerts example

This commit is contained in:
allegroai 2021-05-26 18:30:29 +03:00
parent b1ce3e0653
commit 02fa11c845

View File

@ -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))