lib/slack/smart-bot/comm/get_channels.rb in slack-smart-bot-1.9.2 vs lib/slack/smart-bot/comm/get_channels.rb in slack-smart-bot-1.10.0
- old
+ new
@@ -1,20 +1,35 @@
-def get_channels(bot_is_in: false)
+def get_channels(bot_is_in: false, types: 'private_channel,public_channel')
+ begin
if config.simulate and config.key?(:client)
- if bot_is_in
- client.web_client.conversations_members.reject {|r,v| !v.members.include?(config.nick_id)}.values
- else
- client.web_client.conversations_members.values
- end
+ if bot_is_in
+ client.web_client.conversations_members.reject { |r, v| !v.members.include?(config.nick_id) }.values
+ else
+ client.web_client.conversations_members.values
+ end
else
- if bot_is_in
- client.web_client.users_conversations(exclude_archived: true, limit: 100, types: "im, public_channel,private_channel").channels
- else
- #todo: add pagination for case more than 1000 channels on the workspace
- client.web_client.conversations_list(
- types: "private_channel,public_channel",
- limit: "1000",
- exclude_archived: "true",
- ).channels
+ if bot_is_in
+ client.web_client.users_conversations(exclude_archived: true, limit: 1000, types: "im, public_channel,private_channel").channels
+ else
+ resp = client.web_client.conversations_list(types: types, limit: "600", exclude_archived: "true")
+ channels = resp.channels
+ begin
+ while resp.response_metadata.next_cursor.to_s != ""
+ resp = client.web_client.conversations_list(
+ cursor: resp.response_metadata.next_cursor.to_s,
+ types: types,
+ limit: "600",
+ exclude_archived: "true",
+ )
+ channels += resp.channels
+ end
+ rescue Exception => stack
+ @logger.warn stack
end
+ return channels
+ end
end
-end
\ No newline at end of file
+ rescue Exception => stack
+ @logger.warn stack
+ return []
+ end
+end