공정훈

Combine all questions

Showing 1 changed file with 337 additions and 0 deletions
...@@ -41,6 +41,36 @@ apiRouter.post('/sayHello', function(req, res) { ...@@ -41,6 +41,36 @@ apiRouter.post('/sayHello', function(req, res) {
41 res.status(200).send(responseBody); 41 res.status(200).send(responseBody);
42 }); 42 });
43 43
44 +apiRouter.post('/test', (req, res) => {
45 + const responseBody = {
46 + version: "2.0",
47 + template: {
48 + outputs: [
49 + {
50 + simpleText: {
51 + text: '재밌는 MBTI 테스트'
52 + }
53 + }
54 + ],
55 + quickReplies: [
56 + {
57 + action: "block",
58 + label: "할래!",
59 + message: "할래!",
60 + blockId: "6294c3ecf591aa1905548230"
61 + },
62 + {
63 + action: "block",
64 + label: "안 할래",
65 + message: "안 할래",
66 + blockId: "628b7ef293b31d5b60ab4b29"
67 + }
68 + ]
69 + }
70 + }
71 + res.status(200).send(responseBody);
72 +});
73 +
44 apiRouter.post('/question1', (req, res) => { 74 apiRouter.post('/question1', (req, res) => {
45 var userId = req.body.userRequest.user.id; 75 var userId = req.body.userRequest.user.id;
46 var mesg = req.body.userRequest; 76 var mesg = req.body.userRequest;
...@@ -601,6 +631,238 @@ apiRouter.post('/question8', (req, res) => { ...@@ -601,6 +631,238 @@ apiRouter.post('/question8', (req, res) => {
601 res.status(200).send(responseBody); 631 res.status(200).send(responseBody);
602 }); 632 });
603 633
634 + apiRouter.post('/question15', (req, res) => {
635 + var userId = req.body.userRequest.user.id;
636 + userDB[userId] = ['','','','',''];
637 + const responseBody = {
638 + version: "2.0",
639 + template: {
640 + outputs: [
641 + {
642 + simpleText: {
643 + text: '[Question 15/20]\n친구: 우울해서 아이패드 샀어'
644 + }
645 + }
646 + ],
647 + quickReplies: [
648 + {
649 + action: "block",
650 + label: "왜ㅠㅠ무슨일 있었어?",
651 + message: "왜ㅠㅠ무슨일 있었어?",
652 + blockId: "6294c467e7a0253c7662acac"
653 + },
654 + {
655 + action: "block",
656 + label: "어떤 기종샀어?",
657 + message: "어떤 기종샀어?",
658 + blockId: "6294c467e7a0253c7662acac"
659 + }
660 + ]
661 + }
662 + }
663 + res.status(200).send(responseBody);
664 +});
665 +
666 +apiRouter.post('/question16', (req, res) => {
667 + var userId = req.body.userRequest.user.id;
668 + var mesg = req.body.userRequest.utterance;
669 + var mbti = '';
670 + if (mesg == "왜ㅠㅠ무슨일 있었어?") {
671 + mbti = 'F';
672 + } else if (mesg == "어떤 기종샀어?") {
673 + mbti = 'T';
674 + }
675 + userDB[userId][2] += mbti;
676 + console.log(userDB[userId]);
677 + const responseBody = {
678 + version: "2.0",
679 + template: {
680 + outputs: [
681 + {
682 + simpleText: {
683 + text: '[Question 16/20]\n이메일에 가능한 빨리 회신하려고 하고 지저분한 편지함을 참을 수 없다.'
684 + }
685 + }
686 + ],
687 + quickReplies: [
688 + {
689 + action: "block",
690 + label: "네",
691 + message: "네",
692 + blockId: "6294c4755ceed96c38542a53"
693 + },
694 + {
695 + action: "block",
696 + label: "아니오",
697 + message: "아니오",
698 + blockId: "6294c4755ceed96c38542a53"
699 + }
700 + ]
701 + }
702 + }
703 + res.status(200).send(responseBody);
704 +});
705 +
706 +apiRouter.post('/question17', (req, res) => {
707 + var userId = req.body.userRequest.user.id;
708 + var mesg = req.body.userRequest.utterance;
709 + var mbti = '';
710 + if (mesg == "네") {
711 + mbti = 'J';
712 + } else if (mesg == "아니오") {
713 + mbti = 'P';
714 + }
715 + userDB[userId][3] += mbti;
716 + console.log(userDB[userId]);
717 + const responseBody = {
718 + version: "2.0",
719 + template: {
720 + outputs: [
721 + {
722 + simpleText: {
723 + text: '[Question 17/20]\n당일에 갑자기 잡히는 약속이 부담스럽다.'
724 + }
725 + }
726 + ],
727 + quickReplies: [
728 + {
729 + action: "block",
730 + label: "네",
731 + message: "네",
732 + blockId: "6294c4aff591aa1905548236"
733 + },
734 + {
735 + action: "block",
736 + label: "아니오",
737 + message: "아니오",
738 + blockId: "6294c4aff591aa1905548236"
739 + }
740 + ]
741 + }
742 + }
743 + res.status(200).send(responseBody);
744 +});
745 +
746 +apiRouter.post('/question18', (req, res) => {
747 + var userId = req.body.userRequest.user.id;
748 + var mesg = req.body.userRequest.utterance;
749 + var mbti = '';
750 + if (mesg == "네") {
751 + mbti = 'I';
752 + } else if (mesg == "아니오") {
753 + mbti = 'E';
754 + }
755 + userDB[userId][0] += mbti;
756 + console.log(userDB[userId]);
757 + const responseBody = {
758 + version: "2.0",
759 + template: {
760 + outputs: [
761 + {
762 + simpleText: {
763 + text: '[Question 18/20]\n비행기에 타기 전 만약 비행기에 테러범이 있으면 어떻게 행동할지 상상해봤다.'
764 + }
765 + }
766 + ],
767 + quickReplies: [
768 + {
769 + action: "block",
770 + label: "네",
771 + message: "네",
772 + blockId: "6294c4c2e7a0253c7662acb1"
773 + },
774 + {
775 + action: "block",
776 + label: "아니오",
777 + message: "아니오",
778 + blockId: "6294c4c2e7a0253c7662acb1"
779 + }
780 + ]
781 + }
782 + }
783 + res.status(200).send(responseBody);
784 +});
785 +
786 +apiRouter.post('/question19', (req, res) => {
787 + var userId = req.body.userRequest.user.id;
788 + var mesg = req.body.userRequest.utterance;
789 + var mbti = '';
790 + if (mesg == "네") {
791 + mbti = 'N';
792 + } else if (mesg == "아니오") {
793 + mbti = 'S';
794 + }
795 + userDB[userId][1] += mbti;
796 + console.log(userDB[userId]);
797 + const responseBody = {
798 + version: "2.0",
799 + template: {
800 + outputs: [
801 + {
802 + simpleText: {
803 + text: '[Question 19/20]\n친구가 취업이 안돼서 힘들어하는 상황에 당신의 반응은?'
804 + }
805 + }
806 + ],
807 + quickReplies: [
808 + {
809 + action: "block",
810 + label: "요즘 취업 어렵지 힘들겠다ㅠㅠ",
811 + message: "요즘 취업 어렵지 힘들겠다ㅠㅠ",
812 + blockId: "6294c4c8e7a0253c7662acb3"
813 + },
814 + {
815 + action: "block",
816 + label: "무슨 준비하고있어? 이력서는 넣어봤어?",
817 + message: "무슨 준비하고있어? 이력서는 넣어봤어?",
818 + blockId: "6294c4c8e7a0253c7662acb3"
819 + }
820 + ]
821 + }
822 + }
823 + res.status(200).send(responseBody);
824 +});
825 +
826 +apiRouter.post('/question20', (req, res) => {
827 + var userId = req.body.userRequest.user.id;
828 + var mesg = req.body.userRequest.utterance;
829 + var mbti = '';
830 + if (mesg == "요즘 취업 어렵지 힘들겠다ㅠㅠ") {
831 + mbti = 'F';
832 + } else if (mesg == "무슨 준비하고있어? 이력서는 넣어봤어?") {
833 + mbti = 'T';
834 + }
835 + userDB[userId][2] += mbti;
836 + console.log(userDB[userId]);
837 + const responseBody = {
838 + version: "2.0",
839 + template: {
840 + outputs: [
841 + {
842 + simpleText: {
843 + text: '[Question 20/20]\n마지막 여행지를 향해 가던 중 흥미로운 장소를 발견했을 때, 남은 일정을 고려하는 편이다.'
844 + }
845 + }
846 + ],
847 + quickReplies: [
848 + {
849 + action: "block",
850 + label: "네",
851 + message: "네",
852 + blockId: "6293885b7bd2fd4333583df0"
853 + },
854 + {
855 + action: "block",
856 + label: "아니오",
857 + message: "아니오",
858 + blockId: "6293885b7bd2fd4333583df0"
859 + }
860 + ]
861 + }
862 + }
863 + res.status(200).send(responseBody);
864 +});
865 +
604 apiRouter.post('/result', (req, res) => { 866 apiRouter.post('/result', (req, res) => {
605 var userId = req.body.userRequest.user.id; 867 var userId = req.body.userRequest.user.id;
606 var mesg = req.body.userRequest.utterance; 868 var mesg = req.body.userRequest.utterance;
...@@ -884,6 +1146,81 @@ apiRouter.post('/percent', (req, res) => { ...@@ -884,6 +1146,81 @@ apiRouter.post('/percent', (req, res) => {
884 res.status(200).send(responseBody); 1146 res.status(200).send(responseBody);
885 }); 1147 });
886 1148
1149 +apiRouter.post('/result', (req, res) => {
1150 + var userId = req.body.userRequest.user.id;
1151 + var mesg = req.body.userRequest.utterance;
1152 + var mbti = '';
1153 + if (mesg == "네") {
1154 + mbti = 'J';
1155 + } else if (mesg == "아니오") {
1156 + mbti = 'P';
1157 + }
1158 + userDB[userId][3] += mbti;
1159 + console.log(userDB[userId]);
1160 + analysis_mbti(userDB[userId]);
1161 + const responseBody = {
1162 + version: "2.0",
1163 + template: {
1164 + outputs: [
1165 + {
1166 + simpleText: {
1167 + text: "당신의 MBTI는 : "+userDB[userId][4]
1168 +
1169 + }
1170 + }
1171 + ],
1172 + quickReplies: [{
1173 + action: "block",
1174 + label: "MBTI 테스트 다시하기",
1175 + message: "MBTI 테스트 다시하기",
1176 + blockId : "628b7ef293b31d5b60ab4b29" //to question 1
1177 + }]
1178 + }
1179 + }
1180 + res.status(200).send(responseBody);
1181 +});
1182 +
1183 +function analysis_mbti(userdb) {
1184 + var e = count_mbti(userdb[0], 'E');
1185 + var i = 1-e; //-> 5
1186 + var n = count_mbti(userdb[1], 'N');
1187 + var s = 1-n; //-> 5
1188 + var f = count_mbti(userdb[2], 'F');
1189 + var t = 2-f; //-> 5
1190 + var j = count_mbti(userdb[3], 'J');
1191 + var p = 2-j; //-> 5
1192 + if (e > i) {
1193 + userdb[4] += 'E';
1194 + } else {
1195 + userdb[4] += 'I';
1196 + }
1197 + if (n > s) {
1198 + userdb[4] += 'N';
1199 + } else {
1200 + userdb[4] += 'S';
1201 + }
1202 + if (f > t) {
1203 + userdb[4] += 'F';
1204 + } else {
1205 + userdb[4] += 'T';
1206 + }
1207 + if (j > p) {
1208 + userdb[4] += 'J';
1209 + } else {
1210 + userdb[4] += 'P';
1211 + }
1212 +}
1213 +
1214 +function count_mbti(item_list, mbti_ch) {
1215 + var result = 0;
1216 + for (var i=0; i<5; i++) {
1217 + if(item_list[i] == 'mbti_ch'){
1218 + result += 1;
1219 + }
1220 + }
1221 + return result;
1222 +}
1223 +
887 app.listen((process.env.PORT || 3000), function() { 1224 app.listen((process.env.PORT || 3000), function() {
888 console.log('Example skill server listening on port 3000!'); 1225 console.log('Example skill server listening on port 3000!');
889 }); 1226 });
...\ No newline at end of file ...\ No newline at end of file
......