Skip to content

Instantly share code, notes, and snippets.

Last active July 25, 2019 17:45
What would you like to do?
pick random user from support slack channel
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
.header('Accept', 'application/json')
.get() (err, response, body) ->
channels = JSON.parse(body).channels
supportChannelMembers = channels.filter((c) => == '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: @#{}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment