Created
August 23, 2021 14:28
-
-
Save danielgek/5b23288a78d6afb904af05779f48495d to your computer and use it in GitHub Desktop.
getAllEmailsFromSlackChannel
This file contains hidden or 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 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