-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (76 loc) · 2.07 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
78
79
80
81
82
83
84
85
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
const axios = require("axios").default;
exports.helloWorld = (req, res) => {
//console.log("req.body: ", JSON.stringify(req.body));
let message = req.body.alert_name || "Hello World!";
console.log("alert_name: ", message);
let dic = req.body;
console.log("survey_info: ", req.body.survey_info);
let surveyInfo = dic.survey_info;
let surveyName = surveyInfo.name || "undefined name";
let triggerEvent = dic.trigger_event;
var blocksArray = [
{
type: "section",
text: {
type: "mrkdwn",
text:
"Hey, your *" + surveyName + "* survey got a new response.",
},
},
{
type: "context",
elements: [
{
type: "plain_text",
text: "⚡Triggered by: " + (triggerEvent.event_name || ""),
emoji: true,
},
],
},
];
let screens = surveyInfo.screens;
for (let obj of screens) {
blocksArray.push({
type: "section",
text: {
type: "mrkdwn",
text:
"*" +
obj["title"] +
"* " +
"[" +
obj["type"] +
"] " +
obj["answer"],
},
});
}
blocksArray.push({
type: "section",
text: {
type: "mrkdwn",
text: "<https://dashboard.1flow.app|View results>",
},
});
res.status(200).send(message);
const data = {
blocks: blocksArray,
};
axios
.post(
YOUR_SLACK_INCOMING_WEBHOOK_URL,
data
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
};