From 10698d8efa6203201f1c76e8c004ae7399afd59e Mon Sep 17 00:00:00 2001 From: "Ian C. Ward" Date: Fri, 17 May 2019 10:31:26 -0400 Subject: [PATCH] Fixed #558 - Make Web Client options configurable 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 --- slack.coffee | 3 +++ src/bot.coffee | 1 + src/client.coffee | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/slack.coffee b/slack.coffee index cabfd1c2..e3e11334 100644 --- a/slack.coffee +++ b/slack.coffee @@ -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 diff --git a/src/bot.coffee b/src/bot.coffee index a44ba84a..5c412599 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -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 ### diff --git a/src/client.coffee b/src/client.coffee index fe294956..92d70982 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -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 @@ -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 || {}