-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
172 lines (148 loc) · 4.42 KB
/
bot.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const CONFIG = require("./.config.json");
const testData = require("./testData.json");
const {App} = require("@slack/bolt");
'use strict'
let testLevel = 'greeting';
let isTesting = false;
const btn = {
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: "Press Button",
},
accessory: {
type: "button",
text: {
type: "plain_text",
text: "Start Test",
},
action_id: "button_click",
},
},
],
};
let result = {
attachments: [
{
"mrkdwn_in": ["text"],
"color": "36a64f",
"pretext": "Test Result",
fields: [
{
"title": "성공",
"value": "",
"short": "false"
}
]
},
{
"mrkdwn_in": ["text"],
"color": "bf1f2f",
fields: [
{
"title": "실패",
"value": "",
"short": false
}
]
}
]
}
function check(expression, testMsg) {
(expression) ?
result.attachments[0].fields[0].value += `${testMsg}\n`
: result.attachments[1].fields[0].value += `${testMsg}\n`;
}
function sleep(time) {
return new Promise((res) => setTimeout(res, time));
}
const app = new App({
token: CONFIG.TEST_TOKEN,
signingSecret: CONFIG.TEST_SIGNING_SECRET,
socketMode: true,
appToken: CONFIG.TEST_XAPP,
});
app.message(async ({event, payload}) => {
const {user, text} = event;
// console.log(event);
// console.log(payload);
console.assert(user === CONFIG.MAIN_ID, 'only receive main bot\'s message');
if (!isTesting)
return;
switch (testLevel) {
case 'greeting':
check(testData.greeting_a.toString().includes(text), 'Greeting');
testLevel = 'schedule';
break;
case 'schedule':
check(text === '| 안내 받을 날짜를 입력해주세요 \n' +
'| 형식 : 월/일 (12/13)', '');
testLevel = 'schedule_invalid'
break;
case 'schedule_invalid':
check(text === "올바른 날짜를 입력하세요", 'Schedule (Invalid)');
testLevel = 'schedule_valid';
break;
case 'schedule_valid':
check(text === "12/21 : 종강\n", 'Schedule(Valid)');
testLevel = 'menu_today';
break;
// case 'schedule_empty':
// //check(text === "해당 날짜에는 행사가 없습니다!", 'Schedule (Empty)');
// testLevel = 'schedule_invalid';
// break;
case 'menu_today':
//check(text === , 'Menu (today)');
testLevel = "menu_week";
break;
case 'menu_week':
//check(text.toLowerCase() === 'hi', 'Menu (week)');
testLevel = "dept";
break;
case "dept":
check(text !== null, '');
testLevel = "dept_invalid";
break;
case 'dept_invalid':
check(text === "학과 이름을 올바르게 입력해주세요.", 'Department (Invalid)');
testLevel = 'dept_valid';
break;
case 'dept_valid':
check(text === "College of Engineering Building 7, 224", 'Department (Valid)');
testLevel = 'greeting';
break;
}
});
app.command("/test", async ({ack, say}) => {
await ack();
await say(btn);
});
app.action("button_click", async ({ack, say}) => {
if (isTesting)
return;
await ack();
isTesting = true;
await show(say, "hi");
await show(say, "학사일정");
await show(say, "13/-1");
await show(say, "12/21");
await show(say, "오늘 밥 뭐야");
await show(say, "이번 주 식단");
await show(say, "학과 사무실 안내");
await show(say, "MBA Course Please");
await show(say, "Computer Science and Engineering");
await show(say, result);
result.attachments[0].fields[0].value = '';
result.attachments[1].fields[0].value = '';
isTesting = false;
});
(async () => {
await app.start();
console.log("⚡️ Bolt app is running!");
})();
async function show(say, msg) {
await say(msg);
await sleep(1500);
}