-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const {
WebClient
} = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
function getAllChannels() {
// See: https://api.slack.com/methods/conversations.list#arguments
const param = {
exclude_archived: true,
types: 'public_channel',
// Only get first 100 items
limit: 100
};
return web.conversations.list(param).then(results => {
return results.channels
});
}
const fs = require('fs');
const stream = fs.createWriteStream("channelList.md");
stream.once('open', function (fd) {
stream.write("Name | Topic | Persons\n");
stream.write("----- | ----- | -------\n");
getAllChannels()
.then((res) => {
// `res` contains information about the channels
for (let channel of res.channels) {
const escapedTopic = channel.topic.value.replace(/\r?\n/g, '');
stream.write(`[#${channel.name}](https://mohikanz.slack.com/messages/${channel.name}} | ${escapedTopic} | ${channel.num_members} \n`);
}
stream.end();
})
.catch(console.error);
});