Last active
July 25, 2019 17:45
-
-
Save rjnienaber/31d716f34512562fd3b74f8f0ab73f3e to your computer and use it in GitHub Desktop.
pick random user from support slack channel
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
module.exports = (robot) -> | |
robot.respond /get help/i, (res) -> | |
# get channel list from slack, might require some extra filtering if there's lot of them | |
robot.http("https://slack.com/api/channels.list?token=#{process.env.HUBOT_SLACK_TOKEN}") | |
.header('Accept', 'application/json') | |
.get() (err, response, body) -> | |
channels = JSON.parse(body).channels | |
supportChannelMembers = channels.filter((c) => c.name == 'support')[0].members | |
# filter users by channel and status | |
users = Object.entries(res.robot.adapter.client.rtm.dataStore.users) | |
activeUsers = users.filter((v) => supportChannelMembers.includes(v[0]) && v[1].presence == 'active') | |
.map((v) => v[1]) | |
# pick random user | |
randomActiveUser = activeUsers[Math.floor(Math.random() * activeUsers.length)] | |
res.reply("Random developer for support request: @#{randomActiveUser.name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment