Skip to content

Instantly share code, notes, and snippets.

@benjick
Created February 3, 2017 14:14
Show Gist options
  • Save benjick/8b377f39e8bf6717cccd6d604d6a670c to your computer and use it in GitHub Desktop.
Save benjick/8b377f39e8bf6717cccd6d604d6a670c to your computer and use it in GitHub Desktop.
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