Skip to content

Instantly share code, notes, and snippets.

@danielgek
Created August 23, 2021 14:28
Show Gist options
  • Save danielgek/5b23288a78d6afb904af05779f48495d to your computer and use it in GitHub Desktop.
Save danielgek/5b23288a78d6afb904af05779f48495d to your computer and use it in GitHub Desktop.
getAllEmailsFromSlackChannel
const fetch = require('node-fetch');
const getChannelInfo = async (channelName) => {
return fetch(`https://slack.com/api/conversations.list?token=${TOKEN}`, {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
}, "method": "GET",
}).then(res => res.json()).then(json => {
const channel = json.channels.find(channel => channel.name === channelName)
return {
teamId: channel.shared_team_ids[0],
channelId: channel.id
}
});
}
const getChannelMembers = async (channelID) => {
return fetch(`https://slack.com/api/conversations.members?channel=${channelID}&token=${TOKEN}`, {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
}, "method": "GET",
}).then(res => res.json()).then(json => {
return json.members
});
}
const getUsersDetailsFromTeam = async (teamId) => {
return fetch(`https://slack.com/api/users.list?token=${TOKEN}&team_id=${teamId}`, {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
}, "method": "GET",
}).then(res => res.json()).then((res) => res.members);
}
getChannelInfo('ki_guild_frontend').then(async info => {
console.log(info);
const channelMembers = await getChannelMembers(info.channelId);
console.log(channelMembers)
const slackMembers = await getUsersDetailsFromTeam(info.teamId);
const filteredMembers = slackMembers.filter(sM => channelMembers.includes(sM.id))
console.log(filteredMembers.map(m => m.profile.email).filter(m => !!m));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment