This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (52 loc) · 1.58 KB
/
app.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
const express = require("express");
const cors = require("cors");
const hackedHost = "54.79.19.249";
const bodyParser = require("body-parser");
const chatStates = require("./chatStates");
const slackApi = require("./slackApiWrapers");
const slackState = {};
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
if (process.env.BOT_TOKEN) {
slackApi.setBotToken(process.env.BOT_TOKEN);
console.log("we have set our bot token.");
}
app.get("/", function(req, res) {
res.send("Hello World!");
});
app.post("/event", function(req, res) {
const slackEventDetails = req.body;
console.log("event details", slackEventDetails);
if (
slackEventDetails.event &&
!slackEventDetails.event.bot_id &&
slackEventDetails.event.user &&
!(slackEventDetails.event.user in slackState)
) {
slackState[slackEventDetails.event.user] = {
state: 0
};
const messageTemplate = chatStates.startState(
slackEventDetails.event.user,
slackEventDetails.event.channel,
slackEventDetails.event.text
);
chatStates.postInteractiveStateMessage(
0,
slackEventDetails.event.user,
slackEventDetails.event.channel,
"Hey " + user + " "
);
} else {
console.log("we should post the cancel form and reset life.");
}
});
app.post("/interactive", function(req, res) {
const details = req.body;
if (details.user) console.log("the interactive message details", details);
});
app.listen(3000, "0.0.0.0", function() {
console.log("Example app listening on port 3000!");
});