-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslack.js
62 lines (53 loc) · 1.61 KB
/
slack.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
const token = process.env.SLACKBOT_TOKEN;
const SlackBot = require('slackbots');
const meeting = require('./meeting.js');
const channel = 'general';
const bot = new SlackBot({
token: token,
name: 'Jaxnodebot'
});
// bot.on("start", function() {
// bot.postMessageToChannel(channel, "Hello world!");
// console.log("Hello world!");
// });
bot.on('message', function(data) {
if (data.type !== 'message') {
return;
}
const message_words = data.text.split(' ');
const hasWhat = message_words.filter(w => w.toUpperCase() === 'WHAT');
if (hasWhat.length > 0) {
meeting.what(r => {
const nextMeetingTopic = `<@${data.user}> The next meeting is on '${r}'`;
try {
sendReply(nextMeetingTopic);
} catch (err) {
console.error(err);
}
});
}
const hasWhen = message_words.filter(w => w.toUpperCase() === 'WHEN');
if (hasWhen.length > 0) {
meeting.when(w => {
const neetMeetingTime = `<@${data.user}> Our next meeting will be on ${w}`;
try {
sendReply(neetMeetingTime);
} catch (err) {
console.error(err);
}
});
}
const hasWhere = message_words.filter(w => w.toUpperCase() === 'WHERE');
if (hasWhere.length > 0) {
meeting.where(r => {
try {
sendReply(`<@${data.user}> ${r}`);
} catch (err) {
console.error(err);
}
});
}
});
function sendReply(message) {
bot.postMessageToChannel(channel, message);
}