This repository was archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5184b47
commit 4b72bf5
Showing
1 changed file
with
14 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |