Created
February 3, 2017 14:14
-
-
Save benjick/8b377f39e8bf6717cccd6d604d6a670c 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
import fetch from 'node-fetch'; | |
const channel = 'C03T4C7MS'; | |
const channelInfoUrl = `https://slack.com/api/channels.info?token=${token}&channel=${channel}`; | |
const userListUrl = `https://slack.com/api/users.list?token=${token}`; | |
async function fetchUsers() { | |
try { | |
let usersInChannel = await fetch(channelInfoUrl).then(res => res.json()); | |
usersInChannel = usersInChannel.channel.members; | |
const allUsers = await fetch(userListUrl).then(res => res.json()); | |
const result = usersInChannel.map(userId => { | |
const user = allUsers.members.find(user => user.id === userId); | |
return { | |
name: user.real_name, | |
id: user.id, | |
image: user.profile.image_512 | |
} | |
}) | |
return result; | |
} catch (e) { | |
console.log('e', e); | |
} | |
} | |
fetchUsers().then(users => console.log(users)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment