-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 959 Bytes
/
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
const SlackBot = require("slackbots");
const axios = require("axios");
const dotenv = require("dotenv");
dotenv.config();
const bot = new SlackBot({
token: process.env.SLACK_TOKEN,
name: "nomadbot",
});
bot.on("start", () => {
console.log("nomadbot is running!");
});
bot.on("error", (err) => {
console.log(err);
});
bot.on("message", (data) => {
if (data.type !== "message") {
return;
}
handleMessage(data);
});
const handleMessage = (data) => {
if (data.text.includes("!ping")) {
handlePing(data.channel);
}
};
const handlePing = async (channelId) => {
const channel = await bot.getChannelById(channelId);
try {
const res = await axios.get("https://api.vhomesgroup.com/ping");
const { state, dbState } = res.data;
bot.postMessageToChannel(
channel.name,
`Server is ${state}, database is ${dbState}!`
);
} catch (err) {
bot.postMessageToChannel(channel.name, "Server is down!");
}
};