diff --git a/docs/_posts/2019-04-29-v4.7.0.md b/docs/_posts/2019-04-29-v4.7.0.md new file mode 100644 index 00000000..cfd77861 --- /dev/null +++ b/docs/_posts/2019-04-29-v4.7.0.md @@ -0,0 +1,6 @@ +--- +layout: changelog +--- + +* Adds ability to configure the lifetime of conversation data in the cache using the + `HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS` environment variable (#560) thanks @aoberoi diff --git a/docs/_posts/2019-04-30-v4.7.1.md b/docs/_posts/2019-04-30-v4.7.1.md new file mode 100644 index 00000000..649187cc --- /dev/null +++ b/docs/_posts/2019-04-30-v4.7.1.md @@ -0,0 +1,5 @@ +--- +layout: changelog +--- + +* Fixes an issue parsing the `HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS` as a number (#562) thanks @aoberoi and @mistydemeo diff --git a/package.json b/package.json index be5b0014..f71c06de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-slack", - "version": "4.6.0", + "version": "4.7.1", "description": "A Slack adapter for hubot", "main": "./slack", "scripts": { diff --git a/src/client.coffee b/src/client.coffee index 92d70982..53a1698d 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -10,6 +10,20 @@ class SlackClient ### @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 + # variable. Setting this number higher will reduce the number of requests made to the Web API, which may be helpful if + # your Hubot is experiencing rate limiting errors. However, setting this number too high will result in stale data + # being referenced, and your scripts may experience errors related to channel info (like the name) being incorrect + # after a user changes it in Slack. + # @private + ### + @CONVERSATION_CACHE_TTL_MS = + if process.env.HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS + then parseInt(process.env.HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS, 10) + else (5 * 60 * 1000) + ###* # @constructor # @param {Object} options - Configuration options for this SlackClient instance @@ -241,8 +255,8 @@ class SlackClient # @public ### fetchConversation: (conversationId) -> - # Current date minus 5 minutes (time of expiration for conversation info) - expiration = Date.now() - (5 * 60 * 1000) + # Current date minus time of expiration for conversation info + expiration = Date.now() - SlackClient.CONVERSATION_CACHE_TTL_MS # Check whether conversation is held in client's channelData map and whether information is expired return Promise.resolve(@channelData[conversationId].channel) if @channelData[conversationId]?.channel? and @@ -387,4 +401,7 @@ class SlackClient # @param {Array} results.members ### +if SlackClient.CONVERSATION_CACHE_TTL_MS is NaN + throw new Error('HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS must be a number. It could not be parsed.') + module.exports = SlackClient