Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make PAGE_SIZE configurable for Slack API list calls #612

Merged
merged 7 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports.use = (robot) ->
options =
token: process.env.HUBOT_SLACK_TOKEN
disableUserSync: process.env.DISABLE_USER_SYNC?
apiPageSize: process.env.API_PAGE_SIZE
# reacts to only messages by insalled workspace users in a shared channel
installedTeamOnly: process.env.INSTALLED_TEAM_ONLY?
try
Expand Down
1 change: 1 addition & 0 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SlackBot extends Adapter
# @param {Object} options - configuration options for the adapter
# @param {string} options.token - authentication token for Slack APIs
# @param {Boolean} options.disableUserSync - disables syncing all user data on start
# @param {string} options.apiPageSize - sets Slack API page size
# @param {Boolean} options.installedTeamOnly - reacts to only messages by insalled workspace users in a shared channel
# @param {Object} options.rtm - RTM configuration options for SlackClient
# @param {Object} options.rtmStart - options for `rtm.start` Web API method
Expand Down
15 changes: 7 additions & 8 deletions src/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ Promise = require "bluebird"
SlackFormatter = require "./formatter"

class SlackClient
###*
# Number used for limit when making paginated requests to Slack Web API list methods
# @private
###
@PAGE_SIZE = 100

###*
# Number of milliseconds which the information returned by `conversations.info` is considered to be valid. The default
# value is 5 minutes, and it can be customized by setting the `HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS` environment
Expand All @@ -28,6 +22,7 @@ class SlackClient
# @constructor
# @param {Object} options - Configuration options for this SlackClient instance
# @param {string} options.token - Slack API token for authentication
# @param {string} options.apiPageSize - Number used for limit when making paginated requests to Slack Web API list methods
# @param {Object} [options.rtm={}] - Configuration options for owned RtmClient instance
# @param {Object} [options.rtmStart={}] - Configuration options for RtmClient#start() method
# @param {boolean} [options.noRawText=false] - Deprecated: All SlackTextMessages (subtype of TextMessage) will contain
Expand All @@ -42,6 +37,10 @@ class SlackClient
# this object's API. The property is no longer used internally.
@rtm = new RtmClient options.token, options.rtm
@web = new WebClient options.token, { maxRequestConcurrency: 1 }

@apiPageSize = 100
unless isNaN(options.apiPageSize)
@apiPageSize = parseInt(options.apiPageSize, 10)

@robot.logger.debug "RtmClient initialized with options: #{JSON.stringify(options.rtm)}"
@rtmStartOpts = options.rtmStart || {}
Expand Down Expand Up @@ -217,13 +216,13 @@ class SlackClient
if results?.response_metadata?.next_cursor
# fetch next page
@web.users.list({
limit: SlackClient.PAGE_SIZE,
limit: @apiPageSize,
cursor: results.response_metadata.next_cursor
}, pageLoaded)
else
# pagination complete, run callback with results
callback(null, combinedResults)
@web.users.list({ limit: SlackClient.PAGE_SIZE }, pageLoaded)
@web.users.list({ limit: @apiPageSize }, pageLoaded)

###*
# Fetch user info from the brain. If not available, call users.info
Expand Down