-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (39 loc) · 1.24 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
41
42
43
44
45
46
47
48
const {
LogLevel,
RTMClient,
WebClient
} = require('@slack/client');
const { ENDPOINTS } = require('./constants');
const initialState = require('./initial-state');
const logger = require('./logger');
const getAllSkills = require('./utils/get-all-skills');
const getSites = require('./utils/get-sites');
const getSubscribedChannels = require('./utils/get-subscribed-channels');
const skillsRegistry = [];
const slackAPIToken = process.env.SLACK_BOT_API_TOKEN;
const rtmClient = new RTMClient(slackAPIToken, { logLevel: LogLevel.INFO });
const webClient = new WebClient(slackAPIToken);
(async () => {
const skills = await getAllSkills({ basePath: __dirname });
const subscribedChannels = await getSubscribedChannels(webClient);
const appState = {
...initialState,
clients: {
rtm: rtmClient,
web: webClient
},
endpoints: ENDPOINTS,
sites: getSites(),
subscribedChannels
};
await Promise.all(skills.map(async skill => {
try {
const loadedSkill = await skill(appState);
skillsRegistry[loadedSkill.id] = loadedSkill;
} catch (error) {
logger.error('An error occured attaching a skill.', error);
}
}));
logger.debug('Finished loading skills.', skillsRegistry);
})();
rtmClient.start();