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

Commit

Permalink
Retry msgRoomName up to three times
Browse files Browse the repository at this point in the history
  • Loading branch information
benpbolton committed Nov 9, 2023
1 parent 5184b47 commit 4b72bf5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib/msgRoomName.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# Return the human-readable name of the channel the msg was sent in
# for hubot-slack's breaking change from 3->4 of using ID instead of name
# @param {msg Object}
# @param {next Function} callback
# @param {retryCount Number} number of times this function has been retried
# @return String human-readable name of the channel
module.exports = (msg, next) ->
module.exports = (msg, next, retryCount = 0) ->
if msg.robot.adapterName is "slack"
msg.robot.http("https://slack.com/api/conversations.info")
.query({
channel: msg.message.room
})
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN )
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN)
.get() (err, response, body) ->
channel = JSON.parse(body)
next channel.channel.name
if err || response.ok is false || !response.channel
if retryCount < 3 # Retry up to 3 times
console.warn "Retrying to get channel info for #{msg.message.room}"
console.warn "[Attempt #{retryCount+ 1}]"
module.exports(msg, next, retryCount + 1)
else
console.error "Failed to get channel name after retries for #{msg.message.room}"
next null # Signal failure after retries
else
next response.channel.name
else
next msg.message.room

0 comments on commit 4b72bf5

Please sign in to comment.