-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kohei Ota
committed
Feb 8, 2019
1 parent
17001aa
commit 0bbaff6
Showing
3 changed files
with
304 additions
and
725 deletions.
There are no files selected for viewing
This file contains 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
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); | ||
|
||
}); |
Oops, something went wrong.