-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (68 loc) · 2.54 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { App } = require('@slack/bolt');
const ewelink = require('ewelink-api');
const config = {
slack: {
appToken: 'xapp-1-...',
token: 'xoxb-...',
targetUsername: '',
busyStatuses: ['In a meeting', 'In a huddle', 'in_a_huddle', 'On a call', 'Busy'],
events: {
USER_STATUS_CHANGED: 'user_status_changed',
USER_HUDDLE_CHANGED: 'user_huddle_changed',
}
},
eWeLink: {
email: '',
password: '',
at: '',
apiKey: '',
region: 'eu',
targetDeviceName: 'BusyLight',
targetDeviceId: '',
}
};
const now = () => new Date().toISOString().slice(0, 19).replace('T', ' ');
// TODO: MISSING 'Google Meet call start/end' triggers
(async () => {
const eWeLinkConnection = new ewelink({
// at: config.eWeLink.at,
// apiKey: config.eWeLink.apiKey,
email: config.eWeLink.email,
password: config.eWeLink.password,
region: config.eWeLink.region,
});
/* get all devices */
// const devices = await eWeLinkConnection.getDevices();
// console.log(devices);
// console.log(devices.find(d => d.name === config.eWeLink.targetDeviceName));
// const status = await connection.getDevicePowerState(config.eWeLink.targetDeviceId);
// console.log(status);
const setBusyMode = async (mode) => {
try {
const status = await eWeLinkConnection.setDevicePowerState(config.eWeLink.targetDeviceId, mode ? 'on' : 'off');
console.log('BusyMode: (provided / device)', mode, '/' , status.state, 'at', now());
} catch (e) {
console.error(e?.message || String(e));
}
}
const slackConnection = new App({
token: config.slack.token,
appToken: config.slack.appToken,
socketMode: true,
});
await slackConnection.start();
console.log('⚡️ Slack BOT started ⚡️');
// Slack events
slackConnection.event(config.slack.events.USER_STATUS_CHANGED, async ({ event }) => {
if (event.user.profile.real_name === config.slack.targetUsername) {
console.log(config.slack.events.USER_STATUS_CHANGED, event.user.profile.status_text);
setBusyMode(config.slack.busyStatuses.some(bs => event.user.profile.status_text.toLowerCase().includes(bs.toLowerCase())));
}
});
slackConnection.event(config.slack.events.USER_HUDDLE_CHANGED, async ({ event }) => {
if (event.user.profile.real_name === config.slack.targetUsername) {
console.log(config.slack.events.USER_HUDDLE_CHANGED, event.user.profile.huddle_state);
setBusyMode(config.slack.busyStatuses.some(bs => event.user.profile.huddle_state.toLowerCase().includes(bs.toLowerCase())));
}
});
})();