Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohei Ota committed Feb 8, 2019
1 parent 17001aa commit 0bbaff6
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 725 deletions.
39 changes: 26 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
const { WebClient } = require('@slack/client');
require('dotenv').config();
const {
WebClient
} = require('@slack/client');

// An access token (from your Slack app or custom integration - xoxp, xoxb, or xoxa)
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

// See: https://api.slack.com/methods/channels.list
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.once('open', function (fd) {
stream.write("Name | Topic | Persons\n");
stream.write("----- | ----- | -------\n");

web.channels.list()
.then((res) => {
// `res` contains information about the channels
for (let channel of res.channels) {
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);
}
stream.end();
})
.catch(console.error);

});
Loading

0 comments on commit 0bbaff6

Please sign in to comment.