Minkyung Ko

Merge branch 'feature/question8to14'

Showing 1 changed file with 270 additions and 67 deletions
...@@ -5,6 +5,7 @@ const bodyParser = require('body-parser'); ...@@ -5,6 +5,7 @@ const bodyParser = require('body-parser');
5 5
6 const apiRouter = express.Router(); 6 const apiRouter = express.Router();
7 7
8 +
8 app.use(bodyParser.json()); 9 app.use(bodyParser.json());
9 app.use(bodyParser.urlencoded({ 10 app.use(bodyParser.urlencoded({
10 extended: true 11 extended: true
...@@ -13,47 +14,90 @@ app.use(bodyParser.urlencoded({ ...@@ -13,47 +14,90 @@ app.use(bodyParser.urlencoded({
13 app.use('/api', apiRouter); 14 app.use('/api', apiRouter);
14 15
15 let userDB = new Array(); 16 let userDB = new Array();
17 +let mbtiper = new Array();
16 18
17 -apiRouter.post('/sayHello', function(req, res) { 19 +apiRouter.post('/test', (req, res) => {
18 const responseBody = { 20 const responseBody = {
19 version: "2.0", 21 version: "2.0",
20 template: { 22 template: {
21 outputs: [ 23 outputs: [
22 { 24 {
23 - "basicCard": { 25 + simpleText: {
24 - "title": "MBTI 검사 챗봇", 26 + text: 'MBTI 테스트 question8-14\n시작하려면 시작하기 버튼을 눌러주세요!'
25 - "description": "MBTI 검사 챗봇입니다! \n당신의 MBTI를 찾아보세요!", 27 + }
26 - "thumbnail": { 28 + }
27 - "imageUrl": "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fsnm5S%2Fbtq6cSXUkrD%2FOgk9QsUoPzQGvllliI0CSk%2Fimg.jpg" 29 + ],
30 + quickReplies: [
31 + {
32 + action: "block",
33 + label: "시작하기",
34 + message: "시작하기",
35 + blockId: "62977ff05ceed96c385449b9"
28 }, 36 },
29 - "buttons": [
30 { 37 {
31 - "action": "message", 38 + action: "block",
32 - "label": "MBTI 테스트 시작하기", 39 + label: "나중에 하기",
33 - "messageText": "MBTI 테스트 시작하기" 40 + message: "나중에 하기",
41 + blockId: "6297861be7a0253c7662ccb8"
34 } 42 }
35 ] 43 ]
36 } 44 }
37 } 45 }
46 + res.status(200).send(responseBody);
47 +});
48 +
49 +apiRouter.post('/question8', (req, res) => {
50 + var userId = req.body.userRequest.user.id;
51 + userDB[userId] = ['','','','',''];
52 + console.log(userDB);
53 + const responseBody = {
54 + version: "2.0",
55 + template: {
56 + outputs: [
57 + {
58 + simpleText: {
59 + text: '[question8]\n여행 계획을 어떻게 세우시나요?'
60 + }
61 + }
62 + ],
63 + quickReplies: [
64 + {
65 + action: "block",
66 + label: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
67 + message: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
68 + blockId: "629780e9e7a0253c7662cca6"
69 + },
70 + {
71 + action: "block",
72 + label: "시간과 장소를 자세하게 정한다",
73 + message: "시간과 장소를 자세하게 정한다",
74 + blockId: "629780e9e7a0253c7662cca6"
75 + }
38 ] 76 ]
39 } 77 }
40 - }; 78 + }
41 res.status(200).send(responseBody); 79 res.status(200).send(responseBody);
42 }); 80 });
43 81
44 -apiRouter.post('/question1', (req, res) => { 82 +apiRouter.post('/question9', (req, res) => {
83 + var mesg = req.body.userRequest.utterance;
45 var userId = req.body.userRequest.user.id; 84 var userId = req.body.userRequest.user.id;
46 - var mesg = req.body.userRequest; 85 + var mbti = '';
47 - console.log('[q1:user message] ', mesg); 86 + if (mesg == "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)"){
48 - userDB[userId] = ''; 87 + mbti = 'P';
49 - console.log(userDB[userId]); 88 + }
89 + else if (mesg == "시간과 장소를 자세하게 정한다") {
90 + mbti = 'J';
91 + }
92 + userDB[userId][3] += mbti;
93 + console.log(userDB);
50 const responseBody = { 94 const responseBody = {
51 version: "2.0", 95 version: "2.0",
52 template: { 96 template: {
53 outputs: [ 97 outputs: [
54 { 98 {
55 simpleText: { 99 simpleText: {
56 - text: '사람들과 어울리는 것을 좋아하시나요?' 100 + text: '[question9]\n재미있는 책이나 비디오 게임이 사교 모임보다 더 낫습니다.'
57 } 101 }
58 } 102 }
59 ], 103 ],
...@@ -62,13 +106,13 @@ apiRouter.post('/question1', (req, res) => { ...@@ -62,13 +106,13 @@ apiRouter.post('/question1', (req, res) => {
62 action: "block", 106 action: "block",
63 label: "네", 107 label: "네",
64 message: "네", 108 message: "네",
65 - blockId: "628e8cb07bd2fd433357f878" 109 + blockId: "629780f4ab89e678ee86b2de"
66 }, 110 },
67 { 111 {
68 action: "block", 112 action: "block",
69 label: "아니오", 113 label: "아니오",
70 message: "아니오", 114 message: "아니오",
71 - blockId: "628e8cb07bd2fd433357f878" 115 + blockId: "629780f4ab89e678ee86b2de"
72 } 116 }
73 ] 117 ]
74 } 118 }
...@@ -76,25 +120,25 @@ apiRouter.post('/question1', (req, res) => { ...@@ -76,25 +120,25 @@ apiRouter.post('/question1', (req, res) => {
76 res.status(200).send(responseBody); 120 res.status(200).send(responseBody);
77 }); 121 });
78 122
79 -apiRouter.post('/question2', (req, res) => { 123 +apiRouter.post('/question10', (req, res) => {
80 - var userId = req.body.userRequest.user.id;
81 var mesg = req.body.userRequest.utterance; 124 var mesg = req.body.userRequest.utterance;
82 - console.log('[q2:user message] ', mesg); 125 + var userId = req.body.userRequest.user.id;
83 var mbti = ''; 126 var mbti = '';
84 - if (mesg == "네") { 127 + if (mesg == "네"){
85 - mbti = 'E';
86 - } else if (mesg == "아니오") {
87 mbti = 'I'; 128 mbti = 'I';
88 } 129 }
89 - userDB[userId] += mbti; 130 + else if (mesg == "아니오") {
90 - console.log(userDB[userId]); 131 + mbti = 'E';
132 + }
133 + userDB[userId][0] += mbti;
134 + console.log(userDB);
91 const responseBody = { 135 const responseBody = {
92 version: "2.0", 136 version: "2.0",
93 template: { 137 template: {
94 outputs: [ 138 outputs: [
95 { 139 {
96 simpleText: { 140 simpleText: {
97 - text: '평소 깻잎논쟁에 1시간 이상을 생각해봤다.' 141 + text: '[question10]\n본인이 창의적이기보다 현실적인 사람이라고 생각합니다.'
98 } 142 }
99 } 143 }
100 ], 144 ],
...@@ -103,13 +147,13 @@ apiRouter.post('/question2', (req, res) => { ...@@ -103,13 +147,13 @@ apiRouter.post('/question2', (req, res) => {
103 action: "block", 147 action: "block",
104 label: "네", 148 label: "네",
105 message: "네", 149 message: "네",
106 - blockId: "628d239d93b31d5b60ab6c29" 150 + blockId: "629781015ceed96c385449c8"
107 }, 151 },
108 { 152 {
109 action: "block", 153 action: "block",
110 label: "아니오", 154 label: "아니오",
111 message: "아니오", 155 message: "아니오",
112 - blockId: "628d239d93b31d5b60ab6c29" 156 + blockId: "629781015ceed96c385449c8"
113 } 157 }
114 ] 158 ]
115 } 159 }
...@@ -117,66 +161,66 @@ apiRouter.post('/question2', (req, res) => { ...@@ -117,66 +161,66 @@ apiRouter.post('/question2', (req, res) => {
117 res.status(200).send(responseBody); 161 res.status(200).send(responseBody);
118 }); 162 });
119 163
120 -apiRouter.post('/question3', function(req, res) { 164 +apiRouter.post('/question11', (req, res) => {
121 - var userId = req.body.userRequest.user.id;
122 var mesg = req.body.userRequest.utterance; 165 var mesg = req.body.userRequest.utterance;
123 - console.log('[q3:user message] ', mesg); 166 + var userId = req.body.userRequest.user.id;
124 var mbti = ''; 167 var mbti = '';
125 - if (mesg == '네') { 168 + if (mesg == "네"){
126 - mbti = 'N';
127 - } else if (mesg == '아니오') {
128 mbti = 'S'; 169 mbti = 'S';
129 } 170 }
130 - userDB[userId] += mbti; 171 + else if (mesg == "아니오") {
131 - console.log(userDB[userId]); 172 + mbti = 'N';
173 + }
174 + userDB[userId][1] += mbti;
175 + console.log(userDB);
132 const responseBody = { 176 const responseBody = {
133 version: "2.0", 177 version: "2.0",
134 template: { 178 template: {
135 outputs: [ 179 outputs: [
136 { 180 {
137 - "simpleText": { 181 + simpleText: {
138 - "text": "다음과 같은 상황에서 어떻게 대답하겠습니까?\n 친구: 나 기분 안 좋아서 옷 샀어" 182 + text: '[question11]\n팀플을 하는 경우, 충실하지만 실적을 못 내는 팀원을 제명하기 어려워합니다.'
139 } 183 }
140 } 184 }
141 ], 185 ],
142 quickReplies: [ 186 quickReplies: [
143 { 187 {
144 action: "block", 188 action: "block",
145 - label: "왜 기분 안 좋아?", 189 + label: "네",
146 - message: "왜 기분 안 좋아?", 190 + message: "네",
147 - blockId: "6290630451c40d32c6d8e71f" 191 + blockId: "6297810fe7a0253c7662cca8"
148 }, 192 },
149 { 193 {
150 action: "block", 194 action: "block",
151 - label: "무슨 옷 샀어?", 195 + label: "아니오",
152 - message: "무슨 옷 샀어?", 196 + message: "아니오",
153 - blockId: "6290630451c40d32c6d8e71f" 197 + blockId: "6297810fe7a0253c7662cca8"
154 } 198 }
155 ] 199 ]
156 } 200 }
157 - }; 201 + }
158 res.status(200).send(responseBody); 202 res.status(200).send(responseBody);
159 }); 203 });
160 204
161 -apiRouter.post('/question4', (req, res) => { 205 +apiRouter.post('/question12', (req, res) => {
162 - var userId = req.body.userRequest.user.id;
163 var mesg = req.body.userRequest.utterance; 206 var mesg = req.body.userRequest.utterance;
164 - console.log('[q4:user message] ', mesg); 207 + var userId = req.body.userRequest.user.id;
165 var mbti = ''; 208 var mbti = '';
166 - if (mesg == "왜 기분 안 좋아?") { 209 + if (mesg == "네"){
167 mbti = 'F'; 210 mbti = 'F';
168 - } else if (mesg == "무슨 옷 샀어?") { 211 + }
212 + else if (mesg == "아니오") {
169 mbti = 'T'; 213 mbti = 'T';
170 } 214 }
171 - userDB[userId] += mbti; 215 + userDB[userId][2] += mbti;
172 - console.log(userDB[userId]); 216 + console.log(userDB);
173 const responseBody = { 217 const responseBody = {
174 version: "2.0", 218 version: "2.0",
175 template: { 219 template: {
176 outputs: [ 220 outputs: [
177 { 221 {
178 simpleText: { 222 simpleText: {
179 - text: "그날 할 일에 대해 계획을 미리 세우시나요?" 223 + text: '[question12]\n집과 업무 환경이 잘 정돈되어 있습니다.'
180 } 224 }
181 } 225 }
182 ], 226 ],
...@@ -185,13 +229,13 @@ apiRouter.post('/question4', (req, res) => { ...@@ -185,13 +229,13 @@ apiRouter.post('/question4', (req, res) => {
185 action: "block", 229 action: "block",
186 label: "네", 230 label: "네",
187 message: "네", 231 message: "네",
188 - blockId: "6293885b7bd2fd4333583df0" 232 + blockId: "6297811bf591aa190554a22e"
189 }, 233 },
190 { 234 {
191 action: "block", 235 action: "block",
192 label: "아니오", 236 label: "아니오",
193 message: "아니오", 237 message: "아니오",
194 - blockId: "6293885b7bd2fd4333583df0" 238 + blockId: "6297811bf591aa190554a22e"
195 } 239 }
196 ] 240 ]
197 } 241 }
...@@ -199,25 +243,163 @@ apiRouter.post('/question4', (req, res) => { ...@@ -199,25 +243,163 @@ apiRouter.post('/question4', (req, res) => {
199 res.status(200).send(responseBody); 243 res.status(200).send(responseBody);
200 }); 244 });
201 245
202 -apiRouter.post('/result', (req, res) => { 246 +apiRouter.post('/question13', (req, res) => {
203 - var userId = req.body.userRequest.user.id;
204 var mesg = req.body.userRequest.utterance; 247 var mesg = req.body.userRequest.utterance;
205 - console.log('[result:user message] ', mesg); 248 + var userId = req.body.userRequest.user.id;
206 var mbti = ''; 249 var mbti = '';
207 - if (mesg == "네") { 250 + if (mesg == "네"){
208 mbti = 'J'; 251 mbti = 'J';
209 - } else if (mesg == "아니오") { 252 + }
253 + else if (mesg == "아니오") {
210 mbti = 'P'; 254 mbti = 'P';
211 } 255 }
212 - userDB[userId] += mbti; 256 + userDB[userId][3] += mbti;
213 - console.log(userDB[userId]); 257 + console.log(userDB);
258 + const responseBody = {
259 + version: "2.0",
260 + template: {
261 + outputs: [
262 + {
263 + simpleText: {
264 + text: '[question13]\n친구 관계가 좁고 깊은 편입니다.'
265 + }
266 + }
267 + ],
268 + quickReplies: [
269 + {
270 + action: "block",
271 + label: "네",
272 + message: "네",
273 + blockId: "62978127ab89e678ee86b2e2"
274 + },
275 + {
276 + action: "block",
277 + label: "아니오",
278 + message: "아니오",
279 + blockId: "62978127ab89e678ee86b2e2"
280 + }
281 + ]
282 + }
283 + }
284 + res.status(200).send(responseBody);
285 +});
286 +
287 +apiRouter.post('/question14', (req, res) => {
288 + var mesg = req.body.userRequest.utterance;
289 + var userId = req.body.userRequest.user.id;
290 + var mbti = '';
291 + if (mesg == "네"){
292 + mbti = 'I';
293 + }
294 + else if (mesg == "아니오") {
295 + mbti = 'E';
296 + }
297 + userDB[userId][0] += mbti;
298 + console.log(userDB);
214 const responseBody = { 299 const responseBody = {
215 version: "2.0", 300 version: "2.0",
216 template: { 301 template: {
217 outputs: [ 302 outputs: [
218 { 303 {
219 simpleText: { 304 simpleText: {
220 - text: "당신의 MBTI는 : "+userDB[userId] 305 + text: '[question14]\n공부하기 싫을 때 공부는 왜 해야 하는 것인지 고민에 빠질 때가 있습니다.'
306 + }
307 + }
308 + ],
309 + quickReplies: [
310 + {
311 + action: "block",
312 + label: "네",
313 + message: "네",
314 + blockId: "62979c9ce7a0253c7662ccd4"
315 + },
316 + {
317 + action: "block",
318 + label: "아니오",
319 + message: "아니오",
320 + blockId: "62979c9ce7a0253c7662ccd4"
321 + }
322 + ]
323 + }
324 + }
325 + res.status(200).send(responseBody);
326 +});
327 +
328 +apiRouter.post('/result', (req, res) => {
329 + var mesg = req.body.userRequest.utterance;
330 + var userId = req.body.userRequest.user.id;
331 + mbtiper = ['','','','','','','',''];
332 + var mbti = '';
333 + if (mesg == "네"){
334 + mbti = 'N';
335 + }
336 + else if (mesg == "아니오") {
337 + mbti = 'S';
338 + }
339 + userDB[userId][1] += mbti;
340 + var e = 0;
341 + var n = 0;
342 + var f = 0;
343 + var j = 0;
344 + for(i=0; i<2; i++){
345 + if(userDB[userId][0][i] == "E"){
346 + e++;
347 + }
348 + }
349 + for(i=0; i<2; i++){
350 + if(userDB[userId][1][i] == "N"){
351 + n++;
352 + }
353 + }
354 + for(i=0; i<1; i++){
355 + if(userDB[userId][2][i] == "F"){
356 + f++;
357 + }
358 + }
359 + for(i=0; i<2; i++){
360 + if(userDB[userId][3][i] == "J"){
361 + j++;
362 + }
363 + }
364 + var i = 2-e;
365 + var s = 2-n;
366 + var t = 1-f;
367 + var p = 2-j;
368 + mbtiper[0] += 20 * e;
369 + mbtiper[1] += 20 * i;
370 + mbtiper[2] += 20 * n;
371 + mbtiper[3] += 20 * s;
372 + mbtiper[4] += 20 * t;
373 + mbtiper[5] += 20 * f;
374 + mbtiper[6] += 20 * j;
375 + mbtiper[7] += 20 * p;
376 + if(mbtiper[0]>mbtiper[1]){
377 + userDB[userId][4] += 'E';
378 + } else {
379 + userDB[userId][4] += 'I';
380 + }
381 + if(mbtiper[2]>mbtiper[3]){
382 + userDB[userId][4] += 'N';
383 + } else {
384 + userDB[userId][4] += 'S';
385 + }
386 + if(mbtiper[4]>mbtiper[5]){
387 + userDB[userId][4] += 'T';
388 + } else {
389 + userDB[userId][4] += 'F';
390 + }
391 + if(mbtiper[6]>mbtiper[7]){
392 + userDB[userId][4] += 'J';
393 + } else {
394 + userDB[userId][4] += 'P';
395 + }
396 + const responseBody = {
397 + version: "2.0",
398 + template: {
399 + outputs: [
400 + {
401 + simpleText: {
402 + text: "당신의 MBTI는 : "+userDB[userId][4]
221 } 403 }
222 } 404 }
223 ], 405 ],
...@@ -225,13 +407,34 @@ apiRouter.post('/result', (req, res) => { ...@@ -225,13 +407,34 @@ apiRouter.post('/result', (req, res) => {
225 action: "block", 407 action: "block",
226 label: "MBTI 테스트 다시하기", 408 label: "MBTI 테스트 다시하기",
227 message: "MBTI 테스트 다시하기", 409 message: "MBTI 테스트 다시하기",
228 - blockId : "628b8005055a574d7df54466" 410 + blockId : "62977ff05ceed96c385449b9"
411 + },
412 + {
413 + action: "block",
414 + label: "결과 상세보기",
415 + message: "결과 상세보기",
416 + blockId: "62987b78e7a0253c7662dcd9"
229 }] 417 }]
230 } 418 }
231 } 419 }
232 res.status(200).send(responseBody); 420 res.status(200).send(responseBody);
233 -}); 421 + });
234 422
423 +apiRouter.post('/percent', (req, res) => {
424 + const responseBody = {
425 + version: "2.0",
426 + template: {
427 + outputs: [
428 + {
429 + simpleText: {
430 + text: 'E: '+mbtiper[0]+'%\nI: '+mbtiper[1]+'%\nN: '+mbtiper[2]+'%\nS: '+mbtiper[3]+'%\nT: '+mbtiper[4]+'%\nF: '+mbtiper[5]+'%\nJ: '+mbtiper[6]+'%\nP: '+mbtiper[7]+'%'
431 + }
432 + }
433 + ]
434 + }
435 + }
436 + res.status(200).send(responseBody);
437 + });
235 app.listen((process.env.PORT || 3000), function() { 438 app.listen((process.env.PORT || 3000), function() {
236 console.log('Example skill server listening on port 3000!'); 439 console.log('Example skill server listening on port 3000!');
237 }); 440 });
...\ No newline at end of file ...\ No newline at end of file
......