This repository was archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslack.js
More file actions
67 lines (65 loc) · 2.09 KB
/
Copy pathslack.js
File metadata and controls
67 lines (65 loc) · 2.09 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class slack {
constructor(token, savePath = "./data", jsonspace = 0) {
const fs = require("fs");
console.log(savePath);
if (!fs.existsSync(savePath)) {
fs.mkdirSync(savePath);
}
this.token = token;
this.savePath = savePath;
this.jsonspace = jsonspace;
this.channelIds = {};
const { WebClient, LogLevel } = require("@slack/web-api");
this.client = new WebClient(token, {
logLevel: LogLevel.DEBUG,
});
}
// save slack workspace data
async saveData() {
await this.getChannelsList(); // get the channels list
this.getUsersList(); // get the users list
this.joinChannels(); // join all visible channels
this.saveChannels(); // save channel messages and threads
}
// filter slack data for frontend usages
filterForFrontend() {}
// get channel name -> channel list map
async getChannelsList() {
const channelIds = {};
const getChannelList = require("./src/getChannelList");
const channels = await getChannelList(this.savePath, this.client);
const fs = require("fs");
fs.writeFileSync(
`${this.savePath}/channels.json`,
JSON.stringify(channels, null, this.jsonspace)
);
for (const channel of channels) {
channelIds[channel.name] = channel.id;
}
this.channelIds = channelIds;
fs.writeFileSync(
`${this.savePath}/channels-list.json`,
JSON.stringify(channels, null, this.jsonspace)
);
}
// save users info
getUsersList() {
const getUserList = require("./src/getUserList");
getUserList(this.client, this.savePath, this.jsonspace);
}
// join all channels listed in this.channelIds
joinChannels() {
const joinChannel = require("./src/joinChannel");
for (const [channelName, channelId] of Object.entries(this.channelIds)) {
joinChannel(channelId, this.client);
}
}
// save channels data
saveChannels() {
const saveChannel = require("./src/saveChannel");
for (const [channelName, channelId] of Object.entries(this.channelIds)) {
saveChannel(channelName, channelId, this.client, this.savePath);
}
}
}
module.exports = slack;