forked from lmachens/coaching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.42 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
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const modal = require("./feedback/modal");
const { sendFeedback } = require("./feedback/coda");
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.post("/slack/feedback/modal", async (req, res) => {
try {
const payload = JSON.parse(req.body.payload);
console.log(`Requested ${payload.type} `);
if (payload.type === "view_submission") {
const feedback = Object.values(payload.view.state.values).map((value) => {
const key = Object.keys(value)[0];
const item = value[key];
if (item.type === "radio_buttons" || item.type === "static_select") {
return {
key,
value: item.selected_option ? item.selected_option.value : null,
};
}
return {
key,
value: item.value || "",
};
});
// Do not wait for slow ass coda, because Slack awaits an answer in less than 3 secs
sendFeedback(feedback);
}
if (payload.type === "shortcut") {
await modal.openModal(payload);
}
res.send();
} catch (error) {
console.error(error);
res.status(500).send(error.message);
}
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});