Minkyung Ko

Merge branch

Showing 1 changed file with 456 additions and 0 deletions
...@@ -16,20 +16,61 @@ app.use('/api', apiRouter); ...@@ -16,20 +16,61 @@ app.use('/api', apiRouter);
16 let userDB = new Array(); 16 let userDB = new Array();
17 let mbtiper = new Array(); 17 let mbtiper = new Array();
18 18
19 +<<<<<<< HEAD
19 apiRouter.post('/test', (req, res) => { 20 apiRouter.post('/test', (req, res) => {
21 +=======
22 +apiRouter.post('/sayHello', function(req, res) {
23 + const responseBody = {
24 + version: "2.0",
25 + template: {
26 + outputs: [
27 + {
28 + "basicCard": {
29 + "title": "MBTI 검사 챗봇",
30 + "description": "MBTI 검사 챗봇입니다! \n당신의 MBTI를 찾아보세요!",
31 + "thumbnail": {
32 + "imageUrl": "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fsnm5S%2Fbtq6cSXUkrD%2FOgk9QsUoPzQGvllliI0CSk%2Fimg.jpg"
33 + },
34 + "buttons": [
35 + {
36 + "action": "message",
37 + "label": "MBTI 테스트 시작하기",
38 + "messageText": "MBTI 테스트 시작하기"
39 + }
40 + ]
41 + }
42 + }
43 + ]
44 + }
45 + };
46 + res.status(200).send(responseBody);
47 +});
48 +
49 +apiRouter.post('/question1', (req, res) => {
50 + var userId = req.body.userRequest.user.id;
51 + var mesg = req.body.userRequest;
52 + console.log('[q1:user message] ', mesg);
53 + userDB[userId] = ['','','','',''];
54 + console.log(userDB[userId]);
55 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
20 const responseBody = { 56 const responseBody = {
21 version: "2.0", 57 version: "2.0",
22 template: { 58 template: {
23 outputs: [ 59 outputs: [
24 { 60 {
25 simpleText: { 61 simpleText: {
62 +<<<<<<< HEAD
26 text: 'MBTI 테스트 question8-14\n시작하려면 시작하기 버튼을 눌러주세요!' 63 text: 'MBTI 테스트 question8-14\n시작하려면 시작하기 버튼을 눌러주세요!'
64 +=======
65 + text: '금방 새로운 직장 사람들과 어울리기 시작합니다.'
66 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
27 } 67 }
28 } 68 }
29 ], 69 ],
30 quickReplies: [ 70 quickReplies: [
31 { 71 {
32 action: "block", 72 action: "block",
73 +<<<<<<< HEAD
33 label: "시작하기", 74 label: "시작하기",
34 message: "시작하기", 75 message: "시작하기",
35 blockId: "62977ff05ceed96c385449b9" 76 blockId: "62977ff05ceed96c385449b9"
...@@ -39,6 +80,17 @@ apiRouter.post('/test', (req, res) => { ...@@ -39,6 +80,17 @@ apiRouter.post('/test', (req, res) => {
39 label: "나중에 하기", 80 label: "나중에 하기",
40 message: "나중에 하기", 81 message: "나중에 하기",
41 blockId: "6297861be7a0253c7662ccb8" 82 blockId: "6297861be7a0253c7662ccb8"
83 +=======
84 + label: "네",
85 + message: "네",
86 + blockId: "6297b11ae7a0253c7662ccea"
87 + },
88 + {
89 + action: "block",
90 + label: "아니오",
91 + message: "아니오",
92 + blockId: "6297b11ae7a0253c7662ccea"
93 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
42 } 94 }
43 ] 95 ]
44 } 96 }
...@@ -46,23 +98,44 @@ apiRouter.post('/test', (req, res) => { ...@@ -46,23 +98,44 @@ apiRouter.post('/test', (req, res) => {
46 res.status(200).send(responseBody); 98 res.status(200).send(responseBody);
47 }); 99 });
48 100
101 +<<<<<<< HEAD
49 apiRouter.post('/question8', (req, res) => { 102 apiRouter.post('/question8', (req, res) => {
50 var userId = req.body.userRequest.user.id; 103 var userId = req.body.userRequest.user.id;
51 userDB[userId] = ['','','','','']; 104 userDB[userId] = ['','','','',''];
52 console.log(userDB); 105 console.log(userDB);
53 const responseBody = { 106 const responseBody = {
107 +=======
108 +apiRouter.post('/question2', (req, res) => {
109 + var userId = req.body.userRequest.user.id;
110 + var mesg = req.body.userRequest.utterance;
111 + console.log('[q2:user message] ', mesg);
112 + var mbti = '';
113 + if (mesg == "네") {
114 + mbti = 'E';
115 + } else if (mesg == "아니오") {
116 + mbti = 'I';
117 + }
118 + userDB[userId][0] += mbti;
119 + console.log(userDB[userId]);
120 + const responseBody = {
121 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
54 version: "2.0", 122 version: "2.0",
55 template: { 123 template: {
56 outputs: [ 124 outputs: [
57 { 125 {
58 simpleText: { 126 simpleText: {
127 +<<<<<<< HEAD
59 text: '[question8]\n여행 계획을 어떻게 세우시나요?' 128 text: '[question8]\n여행 계획을 어떻게 세우시나요?'
129 +=======
130 + text: '평소 깻잎논쟁에 대해 1시간 이상을 생각해 보는 편입니다.'
131 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
60 } 132 }
61 } 133 }
62 ], 134 ],
63 quickReplies: [ 135 quickReplies: [
64 { 136 {
65 action: "block", 137 action: "block",
138 +<<<<<<< HEAD
66 label: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)", 139 label: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
67 message: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)", 140 message: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
68 blockId: "629780e9e7a0253c7662cca6" 141 blockId: "629780e9e7a0253c7662cca6"
...@@ -72,6 +145,17 @@ apiRouter.post('/question8', (req, res) => { ...@@ -72,6 +145,17 @@ apiRouter.post('/question8', (req, res) => {
72 label: "시간과 장소를 자세하게 정한다", 145 label: "시간과 장소를 자세하게 정한다",
73 message: "시간과 장소를 자세하게 정한다", 146 message: "시간과 장소를 자세하게 정한다",
74 blockId: "629780e9e7a0253c7662cca6" 147 blockId: "629780e9e7a0253c7662cca6"
148 +=======
149 + label: "네",
150 + message: "네",
151 + blockId: "6297b122ab89e678ee86b331"
152 + },
153 + {
154 + action: "block",
155 + label: "아니오",
156 + message: "아니오",
157 + blockId: "6297b122ab89e678ee86b331"
158 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
75 } 159 }
76 ] 160 ]
77 } 161 }
...@@ -79,6 +163,7 @@ apiRouter.post('/question8', (req, res) => { ...@@ -79,6 +163,7 @@ apiRouter.post('/question8', (req, res) => {
79 res.status(200).send(responseBody); 163 res.status(200).send(responseBody);
80 }); 164 });
81 165
166 +<<<<<<< HEAD
82 apiRouter.post('/question9', (req, res) => { 167 apiRouter.post('/question9', (req, res) => {
83 var mesg = req.body.userRequest.utterance; 168 var mesg = req.body.userRequest.utterance;
84 var userId = req.body.userRequest.user.id; 169 var userId = req.body.userRequest.user.id;
...@@ -91,17 +176,77 @@ apiRouter.post('/question9', (req, res) => { ...@@ -91,17 +176,77 @@ apiRouter.post('/question9', (req, res) => {
91 } 176 }
92 userDB[userId][3] += mbti; 177 userDB[userId][3] += mbti;
93 console.log(userDB); 178 console.log(userDB);
179 +=======
180 +apiRouter.post('/question3', function(req, res) {
181 + var userId = req.body.userRequest.user.id;
182 + var mesg = req.body.userRequest.utterance;
183 + console.log('[q3:user message] ', mesg);
184 + var mbti = '';
185 + if (mesg == '네') {
186 + mbti = 'N';
187 + } else if (mesg == '아니오') {
188 + mbti = 'S';
189 + }
190 + userDB[userId][1] += mbti;
191 + console.log(userDB[userId]);
192 + const responseBody = {
193 + version: "2.0",
194 + template: {
195 + outputs: [
196 + {
197 + "simpleText": {
198 + "text": "토론 시 사람들의 민감한 반응보다 보다 진실을 더 중요시해야 합니다."
199 + }
200 + }
201 + ],
202 + quickReplies: [
203 + {
204 + action: "block",
205 + label: "네",
206 + message: "네",
207 + blockId: "6297b1275ceed96c38544a08"
208 + },
209 + {
210 + action: "block",
211 + label: "아니오",
212 + message: "아니오",
213 + blockId: "6297b1275ceed96c38544a08"
214 + }
215 + ]
216 + }
217 + };
218 + res.status(200).send(responseBody);
219 +});
220 +
221 +apiRouter.post('/question4', (req, res) => {
222 + var userId = req.body.userRequest.user.id;
223 + var mesg = req.body.userRequest.utterance;
224 + console.log('[q4:user message] ', mesg);
225 + var mbti = '';
226 + if (mesg == "네") {
227 + mbti = 'T';
228 + } else if (mesg == "아니오") {
229 + mbti = 'F';
230 + }
231 + userDB[userId][2] += mbti;
232 + console.log(userDB[userId]);
233 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
94 const responseBody = { 234 const responseBody = {
95 version: "2.0", 235 version: "2.0",
96 template: { 236 template: {
97 outputs: [ 237 outputs: [
98 { 238 {
99 simpleText: { 239 simpleText: {
240 +<<<<<<< HEAD
100 text: '[question9]\n재미있는 책이나 비디오 게임이 사교 모임보다 더 낫습니다.' 241 text: '[question9]\n재미있는 책이나 비디오 게임이 사교 모임보다 더 낫습니다.'
242 +=======
243 + text: "주의깊게 미리 계획하기 보다는 즉흥적으로 움직입니다."
244 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
101 } 245 }
102 } 246 }
103 ], 247 ],
104 quickReplies: [ 248 quickReplies: [
249 +<<<<<<< HEAD
105 { 250 {
106 action: "block", 251 action: "block",
107 label: "네", 252 label: "네",
...@@ -320,6 +465,144 @@ apiRouter.post('/question14', (req, res) => { ...@@ -320,6 +465,144 @@ apiRouter.post('/question14', (req, res) => {
320 blockId: "62979c9ce7a0253c7662ccd4" 465 blockId: "62979c9ce7a0253c7662ccd4"
321 } 466 }
322 ] 467 ]
468 +=======
469 + {
470 + action: "block",
471 + label: "네",
472 + message: "네",
473 + blockId: "6297b12be7a0253c7662ccec"
474 + },
475 + {
476 + action: "block",
477 + label: "아니오",
478 + message: "아니오",
479 + blockId: "6297b12be7a0253c7662ccec"
480 + }
481 + ]
482 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
483 + }
484 + }
485 + res.status(200).send(responseBody);
486 +});
487 +
488 +apiRouter.post('/question5', (req, res) => {
489 + var userId = req.body.userRequest.user.id;
490 + var mesg = req.body.userRequest;
491 + console.log('[q1:user message] ', mesg);
492 + var mbti = '';
493 + if (mesg == "네") {
494 + mbti = 'P';
495 + } else if (mesg == "아니오") {
496 + mbti = 'J';
497 + }
498 + userDB[userId][3] += mbti;
499 + console.log(userDB[userId]);
500 + const responseBody = {
501 + version: "2.0",
502 + template: {
503 + outputs: [
504 + {
505 + simpleText: {
506 + text: '주목받는 것을 좋아합니다.'
507 + }
508 + }
509 + ],
510 + quickReplies: [
511 + {
512 + action: "block",
513 + label: "네",
514 + message: "네",
515 + blockId: "6297b130e7a0253c7662ccee"
516 + },
517 + {
518 + action: "block",
519 + label: "아니오",
520 + message: "아니오",
521 + blockId: "6297b130e7a0253c7662ccee"
522 + }
523 + ]
524 + }
525 + }
526 + res.status(200).send(responseBody);
527 +});
528 +
529 +apiRouter.post('/question6', (req, res) => {
530 + var userId = req.body.userRequest.user.id;
531 + var mesg = req.body.userRequest.utterance;
532 + console.log('[q2:user message] ', mesg);
533 + var mbti = '';
534 + if (mesg == "네") {
535 + mbti = 'E';
536 + } else if (mesg == "아니오") {
537 + mbti = 'I';
538 + }
539 + userDB[userId][0] += mbti;
540 + console.log(userDB[userId]);
541 + const responseBody = {
542 + version: "2.0",
543 + template: {
544 + outputs: [
545 + {
546 + simpleText: {
547 + text: '종종 인간 실존에 대한 이유를 생각합니다.'
548 + }
549 + }
550 + ],
551 + quickReplies: [
552 + {
553 + action: "block",
554 + label: "네",
555 + message: "네",
556 + blockId: "6297b133f591aa190554a260"
557 + },
558 + {
559 + action: "block",
560 + label: "아니오",
561 + message: "아니오",
562 + blockId: "6297b133f591aa190554a260"
563 + }
564 + ]
565 + }
566 + }
567 + res.status(200).send(responseBody);
568 +});
569 +
570 +apiRouter.post('/question7', (req, res) => {
571 + var userId = req.body.userRequest.user.id;
572 + var mesg = req.body.userRequest.utterance;
573 + console.log('[q2:user message] ', mesg);
574 + var mbti = '';
575 + if (mesg == "네") {
576 + mbti = 'N';
577 + } else if (mesg == "아니오") {
578 + mbti = 'S';
579 + }
580 + userDB[userId][1] += mbti;
581 + console.log(userDB[userId]);
582 + const responseBody = {
583 + version: "2.0",
584 + template: {
585 + outputs: [
586 + {
587 + simpleText: {
588 + text: '어떤 일에서 성과를 냈을 때 “고생했어”보다 “잘했어”라는 말이 더 좋습니다.'
589 + }
590 + }
591 + ],
592 + quickReplies: [
593 + {
594 + action: "block",
595 + label: "네",
596 + message: "네",
597 + blockId: "6297b3505ceed96c38544a0a"
598 + },
599 + {
600 + action: "block",
601 + label: "아니오",
602 + message: "아니오",
603 + blockId: "6297b3505ceed96c38544a0a"
604 + }
605 + ]
323 } 606 }
324 } 607 }
325 res.status(200).send(responseBody); 608 res.status(200).send(responseBody);
...@@ -328,6 +611,7 @@ apiRouter.post('/question14', (req, res) => { ...@@ -328,6 +611,7 @@ apiRouter.post('/question14', (req, res) => {
328 apiRouter.post('/result', (req, res) => { 611 apiRouter.post('/result', (req, res) => {
329 var mesg = req.body.userRequest.utterance; 612 var mesg = req.body.userRequest.utterance;
330 var userId = req.body.userRequest.user.id; 613 var userId = req.body.userRequest.user.id;
614 +<<<<<<< HEAD
331 mbtiper = ['','','','','','','','']; 615 mbtiper = ['','','','','','','',''];
332 var mbti = ''; 616 var mbti = '';
333 if (mesg == "네"){ 617 if (mesg == "네"){
...@@ -435,6 +719,178 @@ apiRouter.post('/percent', (req, res) => { ...@@ -435,6 +719,178 @@ apiRouter.post('/percent', (req, res) => {
435 } 719 }
436 res.status(200).send(responseBody); 720 res.status(200).send(responseBody);
437 }); 721 });
722 +=======
723 + var mesg = req.body.userRequest.utterance;
724 + console.log('[result:user message] ', mesg);
725 + var mbti = '';
726 + if (mesg == "네") {
727 + mbti = 'T';
728 + } else if (mesg == "아니오") {
729 + mbti = 'F';
730 + }
731 + userDB[userId][2] += mbti;
732 + console.log(userDB[userId]);
733 + result(userDB[userId]);
734 + const responseBody = {
735 + version: "2.0",
736 + template: {
737 + outputs: [
738 + {
739 + simpleText: {
740 + text: "당신의 MBTI는 : "+userDB[userId][4]
741 + }
742 + }
743 + ],
744 + quickReplies: [{
745 + action: "block",
746 + label: "MBTI 테스트 다시하기",
747 + message: "MBTI 테스트 다시하기",
748 + blockId : "6297b10d5ceed96c38544a06"
749 + },
750 + {
751 + action: "block",
752 + label: "자세한 결과 보기",
753 + message: "자세한 결과 보기",
754 + blockId: "6297bc58ab89e678ee86b33a"
755 + }]
756 + }
757 + }
758 + res.status(200).send(responseBody);
759 +});
760 +
761 +apiRouter.post('/detail', (req, res) => {
762 + var userId = req.body.userRequest.user.id;
763 + var mesg = req.body.userRequest.utterance;
764 + var E=0;
765 + var I=0;
766 + var N=0;
767 + var S=0;
768 + var F=0;
769 + var T=0;
770 + var P=0;
771 + var J=0;
772 +
773 + for(let j=0;j<4;j++){
774 + for(let i=0; i<3; i++){
775 + if(j==0){
776 + if(userDB[userId][j][i]=="E"){
777 + E++;
778 + }
779 + else{
780 + I++;
781 + }
782 + }
783 + else if(j==1){
784 + if(userDB[userId][j][i]=="N"){
785 + N++;
786 + }
787 + else{
788 + S++;
789 + }
790 + }
791 + else if(j==2){
792 + if(userDB[userId][j][i]=="F"){
793 + F++;
794 + }
795 + else{
796 + T++;
797 + }
798 + }
799 + else if(j==3){
800 + if(userDB[userId][j][i]=="N"){
801 + P++;
802 + }
803 + else{
804 + J++;
805 + }
806 + }
807 + }
808 + }
809 +
810 + const responseBody = {
811 + version: "2.0",
812 + template: {
813 + outputs: [
814 + {
815 + simpleText: {
816 + text: "E와 I의 비율\nE : "+(E/(E+I)*100)+"%\nI : "+(I/(E+I)*100)+"\nN와 S의 비율\nN : "+(N/(N+S)*100)+"%\nS : "+(S/(N+S)*100)+"\nF와 T의 비율\nF : "+(F/(F+T)*100)+"%\nT : "+(T/(F+T)*100)+"\nJ와 P의 비율\nJ : "+(J/(J+P)*100)+"%\nP : "+(P/(J+P)*100)
817 + }
818 + }
819 + ]
820 + }
821 + }
822 + res.status(200).send(responseBody);
823 +});
824 +
825 +function result(Array){
826 + var E=0;
827 + var I=0;
828 + var N=0;
829 + var S=0;
830 + var F=0;
831 + var T=0;
832 + var P=0;
833 + var J=0;
834 +
835 + for(let j=0;j<4;j++){
836 + for(let i=0; i<3; i++){
837 + if(j==0){
838 + if(Array[j][i]=="E"){
839 + E++;
840 + }
841 + else{
842 + I++;
843 + }
844 + }
845 + else if(j==1){
846 + if(Array[j][i]=="N"){
847 + N++;
848 + }
849 + else{
850 + S++;
851 + }
852 + }
853 + else if(j==2){
854 + if(Array[j][i]=="F"){
855 + F++;
856 + }
857 + else{
858 + T++;
859 + }
860 + }
861 + else if(j==3){
862 + if(Array[j][i]=="N"){
863 + P++;
864 + }
865 + else{
866 + J++;
867 + }
868 + }
869 + }
870 + }
871 +
872 + if(E>I)
873 + Array[4]+='E';
874 + else
875 + Array[4]+='I';
876 +
877 + if(N>S)
878 + Array[4]+='N';
879 + else
880 + Array[4]+='S';
881 +
882 + if(F>T)
883 + Array[4]+='F';
884 + else
885 + Array[4]+='T';
886 +
887 + if(P>J)
888 + Array[4]+='P';
889 + else
890 + Array[4]+='J';
891 +}
892 +
893 +>>>>>>> 9cc768840e30632a42343600db176f035dc0ebf9
438 app.listen((process.env.PORT || 3000), function() { 894 app.listen((process.env.PORT || 3000), function() {
439 console.log('Example skill server listening on port 3000!'); 895 console.log('Example skill server listening on port 3000!');
440 }); 896 });
...\ No newline at end of file ...\ No newline at end of file
......