From a5d67e24343bc18805fb3924176cc6dd29014436 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Mon, 29 Apr 2019 14:01:57 -0700 Subject: [PATCH 1/5] allows users to configure the TTL of the responses from conversations.info --- src/client.coffee | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/client.coffee b/src/client.coffee index fe294956..599a2b0c 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -10,6 +10,17 @@ 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 = process.env.HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS || (5 * 60 * 1000) + ###* # @constructor # @param {Object} options - Configuration options for this SlackClient instance @@ -238,8 +249,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 From 129eb8b6e15bfaa8ebad86d1bef10ecb0e06f8e5 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Mon, 29 Apr 2019 14:56:12 -0700 Subject: [PATCH 2/5] v4.7.0 --- docs/_posts/2019-04-29-v4.7.0.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 docs/_posts/2019-04-29-v4.7.0.md 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/package.json b/package.json index be5b0014..aa4899ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-slack", - "version": "4.6.0", + "version": "4.7.0", "description": "A Slack adapter for hubot", "main": "./slack", "scripts": { From b32d81f859d85c534d550d843cc811259f8258d6 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Tue, 30 Apr 2019 16:27:57 -0700 Subject: [PATCH 3/5] fix issue with using a string from env vars as a number --- src/client.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client.coffee b/src/client.coffee index 599a2b0c..ab74ba15 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -13,13 +13,16 @@ class SlackClient ###* # 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 + # 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 = process.env.HUBOT_SLACK_CONVERSATION_CACHE_TTL_MS || (5 * 60 * 1000) + @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 From 79b16a532ab7eded0b5db9932333a029d2725133 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Tue, 30 Apr 2019 17:15:10 -0700 Subject: [PATCH 4/5] guard against NaN --- src/client.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client.coffee b/src/client.coffee index ab74ba15..5ef1128a 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -398,4 +398,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 From de7cd6833617162b699cf948272aad929b91c3b6 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Tue, 30 Apr 2019 17:26:18 -0700 Subject: [PATCH 5/5] v4.7.1 --- docs/_posts/2019-04-30-v4.7.1.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 docs/_posts/2019-04-30-v4.7.1.md 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 aa4899ef..f71c06de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-slack", - "version": "4.7.0", + "version": "4.7.1", "description": "A Slack adapter for hubot", "main": "./slack", "scripts": {