Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 4b72bf5

Browse files
committed
Retry msgRoomName up to three times
1 parent 5184b47 commit 4b72bf5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lib/msgRoomName.coffee

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Return the human-readable name of the channel the msg was sent in
22
# for hubot-slack's breaking change from 3->4 of using ID instead of name
33
# @param {msg Object}
4+
# @param {next Function} callback
5+
# @param {retryCount Number} number of times this function has been retried
46
# @return String human-readable name of the channel
5-
module.exports = (msg, next) ->
7+
module.exports = (msg, next, retryCount = 0) ->
68
if msg.robot.adapterName is "slack"
79
msg.robot.http("https://slack.com/api/conversations.info")
810
.query({
911
channel: msg.message.room
1012
})
11-
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN )
13+
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN)
1214
.get() (err, response, body) ->
13-
channel = JSON.parse(body)
14-
next channel.channel.name
15+
if err || response.ok is false || !response.channel
16+
if retryCount < 3 # Retry up to 3 times
17+
console.warn "Retrying to get channel info for #{msg.message.room}"
18+
console.warn "[Attempt #{retryCount+ 1}]"
19+
module.exports(msg, next, retryCount + 1)
20+
else
21+
console.error "Failed to get channel name after retries for #{msg.message.room}"
22+
next null # Signal failure after retries
23+
else
24+
next response.channel.name
1525
else
1626
next msg.message.room

0 commit comments

Comments
 (0)