Skip to content

Commit

Permalink
Merge pull request #612 from kintarowins/patch-1
Browse files Browse the repository at this point in the history
make PAGE_SIZE configurable for Slack API list calls
  • Loading branch information
seratch authored Jan 27, 2021
2 parents 00edee0 + 476fca6 commit 767900a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
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

0 comments on commit 767900a

Please sign in to comment.