Skip to content

Commit

Permalink
Fixed slackapi#558 - Make Web Client options configurable
Browse files Browse the repository at this point in the history
Add new HUBOT_SLACK_WEB_CLIENT_OPTS environment variable, used to
configure web client options; It should be functionally similar to
HUBOT_SLACK_RTM_CLIENT_OPTS, which is used to configure the RTM Client
  • Loading branch information
iancward committed May 17, 2019
1 parent e3acc28 commit 10698d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ exports.use = (robot) ->
options =
token: process.env.HUBOT_SLACK_TOKEN
disableUserSync: process.env.DISABLE_USER_SYNC?
try
options.web = JSON.parse(process.env.HUBOT_SLACK_WEB_CLIENT_OPTS)
catch
try
options.rtm = JSON.parse(process.env.HUBOT_SLACK_RTM_CLIENT_OPTS)
catch
Expand Down
1 change: 1 addition & 0 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 {Object} options.web - Web configuration options for SlackClient
# @param {Object} options.rtm - RTM configuration options for SlackClient
# @param {Object} options.rtmStart - options for `rtm.start` Web API method
###
Expand Down
5 changes: 4 additions & 1 deletion src/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SlackClient
# @constructor
# @param {Object} options - Configuration options for this SlackClient instance
# @param {string} options.token - Slack API token for authentication
# @param {Object] [options.web={}] - Configuration options for owned WebClient instance
# @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 @@ -27,8 +28,10 @@ class SlackClient
# @rtm.dataStore property is publically accessible, so the recommended settings cannot be used without breaking
# 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 }

@web = new WebClient options.token, options.web

@robot.logger.debug "WebClient initialized with options: #{JSON.stringify(options.web)}"
@robot.logger.debug "RtmClient initialized with options: #{JSON.stringify(options.rtm)}"
@rtmStartOpts = options.rtmStart || {}

Expand Down

0 comments on commit 10698d8

Please sign in to comment.