Created
October 9, 2018 07:54
-
-
Save rch850/6daadbf88a657ef82bb87f1cc1040ea5 to your computer and use it in GitHub Desktop.
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
const process = require('process') | |
const https = require('https') | |
const slackToken = process.env.SLACK_TOKEN | |
if (!process.env.SLACK_TOKEN) { | |
console.error('Environment variable SLACK_TOKEN is empty!') | |
process.exit(1) | |
} | |
if (!process.argv[2]) { | |
console.error('usage: node slack-reactions.js MESSAGE_URL') | |
process.exit(2) | |
} | |
function get(url) { | |
let body = '' | |
return new Promise((resolve, reject) => { | |
https.get(url, (res) => { | |
res.on('data', (chunk) => { | |
body += chunk | |
}) | |
res.on('end', () => { | |
resolve({data: JSON.parse(body)}) | |
}) | |
}) | |
}) | |
} | |
function parseMessageUrl(url) { | |
// message url example: | |
// https://your-workspace-name.slack.com/archives/C1234567890/p1536906698000100 | |
let m = url.match(/.*archives\/(\w+)\/p(\d+)/) | |
return { | |
channel: m[1], | |
messageTs: Number(m[2]) / 1000000 | |
} | |
} | |
async function run() { | |
let { channel, messageTs } = parseMessageUrl(process.argv[2]) | |
const messageTsPlus = messageTs + 1 | |
try { | |
const history = await get(`https://slack.com/api/channels.history?token=${slackToken}&latest=${messageTsPlus}&oldest=${messageTs}&channel=${channel}`) | |
history.data.messages[0].reactions.forEach(reaction => { | |
reaction.users.forEach(async (userKey) => { | |
const user = await get(`https://slack.com/api/users.info?token=${slackToken}&user=${userKey}`) | |
console.log(user.data.user.profile.real_name) | |
}) | |
}) | |
} catch (e) { | |
} | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment