Minkyung Ko

Add start & question8

Showing 1 changed file with 26 additions and 149 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
...@@ -12,7 +13,14 @@ app.use(bodyParser.urlencoded({ ...@@ -12,7 +13,14 @@ app.use(bodyParser.urlencoded({
12 13
13 app.use('/api', apiRouter); 14 app.use('/api', apiRouter);
14 15
15 -let userDB = new Array(); 16 +function createArray(rows, columns) {
17 + var arr = new Array(rows);
18 + for (var i = 0; i < rows; i++) {
19 + arr[i] = new Array(columns);
20 + }
21 + return arr;
22 +}
23 +var userDB = createArray(5, 5);
16 24
17 apiRouter.post('/sayHello', function(req, res) { 25 apiRouter.post('/sayHello', function(req, res) {
18 const responseBody = { 26 const responseBody = {
...@@ -41,34 +49,29 @@ apiRouter.post('/sayHello', function(req, res) { ...@@ -41,34 +49,29 @@ apiRouter.post('/sayHello', function(req, res) {
41 res.status(200).send(responseBody); 49 res.status(200).send(responseBody);
42 }); 50 });
43 51
44 -apiRouter.post('/question1', (req, res) => { 52 +apiRouter.post('/test', (req, res) => {
45 - var userId = req.body.userRequest.user.id;
46 - var mesg = req.body.userRequest;
47 - console.log('[q1:user message] ', mesg);
48 - userDB[userId] = '';
49 - console.log(userDB[userId]);
50 const responseBody = { 53 const responseBody = {
51 version: "2.0", 54 version: "2.0",
52 template: { 55 template: {
53 outputs: [ 56 outputs: [
54 { 57 {
55 simpleText: { 58 simpleText: {
56 - text: '사람들과 어울리는 것을 좋아하시나요?' 59 + text: 'MBTI 테스트 question8-14'
57 } 60 }
58 } 61 }
59 ], 62 ],
60 quickReplies: [ 63 quickReplies: [
61 { 64 {
62 action: "block", 65 action: "block",
63 - label: "", 66 + label: "시작하기",
64 - message: "", 67 + message: "시작하기",
65 - blockId: "628e8cb07bd2fd433357f878" 68 + blockId: "62977ff05ceed96c385449b9"
66 }, 69 },
67 { 70 {
68 action: "block", 71 action: "block",
69 - label: "아니오", 72 + label: "나중에 하기",
70 - message: "아니오", 73 + message: "나중에 하기",
71 - blockId: "628e8cb07bd2fd433357f878" 74 + blockId: "6297861be7a0253c7662ccb8"
72 } 75 }
73 ] 76 ]
74 } 77 }
...@@ -76,40 +79,29 @@ apiRouter.post('/question1', (req, res) => { ...@@ -76,40 +79,29 @@ apiRouter.post('/question1', (req, res) => {
76 res.status(200).send(responseBody); 79 res.status(200).send(responseBody);
77 }); 80 });
78 81
79 -apiRouter.post('/question2', (req, res) => { 82 +apiRouter.post('/question8', (req, res) => {
80 - var userId = req.body.userRequest.user.id; 83 + const responseBody = {
81 - var mesg = req.body.userRequest.utterance;
82 - console.log('[q2:user message] ', mesg);
83 - var mbti = '';
84 - if (mesg == "네") {
85 - mbti = 'E';
86 - } else if (mesg == "아니오") {
87 - mbti = 'I';
88 - }
89 - userDB[userId] += mbti;
90 - console.log(userDB[userId]);
91 - const responseBody = {
92 version: "2.0", 84 version: "2.0",
93 template: { 85 template: {
94 outputs: [ 86 outputs: [
95 { 87 {
96 simpleText: { 88 simpleText: {
97 - text: '평소 깻잎논쟁에 1시간 이상을 생각해봤다.' 89 + text: '[question8]\n여행 계획을 어떻게 세우시나요?'
98 } 90 }
99 } 91 }
100 ], 92 ],
101 quickReplies: [ 93 quickReplies: [
102 { 94 {
103 action: "block", 95 action: "block",
104 - label: "", 96 + label: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
105 - message: "", 97 + message: "테마만 정한다(ex.맛집 방문하는 날, 사진 찍는 날)",
106 - blockId: "628d239d93b31d5b60ab6c29" 98 + blockId: "629780e9e7a0253c7662cca6"
107 }, 99 },
108 { 100 {
109 action: "block", 101 action: "block",
110 - label: "아니오", 102 + label: "시간과 장소를 자세하게 정한다",
111 - message: "아니오", 103 + message: "시간과 장소를 자세하게 정한다",
112 - blockId: "628d239d93b31d5b60ab6c29" 104 + blockId: "629780e9e7a0253c7662cca6"
113 } 105 }
114 ] 106 ]
115 } 107 }
...@@ -117,121 +109,6 @@ apiRouter.post('/question2', (req, res) => { ...@@ -117,121 +109,6 @@ apiRouter.post('/question2', (req, res) => {
117 res.status(200).send(responseBody); 109 res.status(200).send(responseBody);
118 }); 110 });
119 111
120 -apiRouter.post('/question3', function(req, res) {
121 - var userId = req.body.userRequest.user.id;
122 - var mesg = req.body.userRequest.utterance;
123 - console.log('[q3:user message] ', mesg);
124 - var mbti = '';
125 - if (mesg == '네') {
126 - mbti = 'N';
127 - } else if (mesg == '아니오') {
128 - mbti = 'S';
129 - }
130 - userDB[userId] += mbti;
131 - console.log(userDB[userId]);
132 - const responseBody = {
133 - version: "2.0",
134 - template: {
135 - outputs: [
136 - {
137 - "simpleText": {
138 - "text": "다음과 같은 상황에서 어떻게 대답하겠습니까?\n 친구: 나 기분 안 좋아서 옷 샀어"
139 - }
140 - }
141 - ],
142 - quickReplies: [
143 - {
144 - action: "block",
145 - label: "왜 기분 안 좋아?",
146 - message: "왜 기분 안 좋아?",
147 - blockId: "6290630451c40d32c6d8e71f"
148 - },
149 - {
150 - action: "block",
151 - label: "무슨 옷 샀어?",
152 - message: "무슨 옷 샀어?",
153 - blockId: "6290630451c40d32c6d8e71f"
154 - }
155 - ]
156 - }
157 - };
158 - res.status(200).send(responseBody);
159 -});
160 -
161 -apiRouter.post('/question4', (req, res) => {
162 - var userId = req.body.userRequest.user.id;
163 - var mesg = req.body.userRequest.utterance;
164 - console.log('[q4:user message] ', mesg);
165 - var mbti = '';
166 - if (mesg == "왜 기분 안 좋아?") {
167 - mbti = 'F';
168 - } else if (mesg == "무슨 옷 샀어?") {
169 - mbti = 'T';
170 - }
171 - userDB[userId] += mbti;
172 - console.log(userDB[userId]);
173 - const responseBody = {
174 - version: "2.0",
175 - template: {
176 - outputs: [
177 - {
178 - simpleText: {
179 - text: "그날 할 일에 대해 계획을 미리 세우시나요?"
180 - }
181 - }
182 - ],
183 - quickReplies: [
184 - {
185 - action: "block",
186 - label: "네",
187 - message: "네",
188 - blockId: "6293885b7bd2fd4333583df0"
189 - },
190 - {
191 - action: "block",
192 - label: "아니오",
193 - message: "아니오",
194 - blockId: "6293885b7bd2fd4333583df0"
195 - }
196 - ]
197 - }
198 - }
199 - res.status(200).send(responseBody);
200 -});
201 -
202 -apiRouter.post('/result', (req, res) => {
203 - var userId = req.body.userRequest.user.id;
204 - var mesg = req.body.userRequest.utterance;
205 - console.log('[result:user message] ', mesg);
206 - var mbti = '';
207 - if (mesg == "네") {
208 - mbti = 'J';
209 - } else if (mesg == "아니오") {
210 - mbti = 'P';
211 - }
212 - userDB[userId] += mbti;
213 - console.log(userDB[userId]);
214 - const responseBody = {
215 - version: "2.0",
216 - template: {
217 - outputs: [
218 - {
219 - simpleText: {
220 - text: "당신의 MBTI는 : "+userDB[userId]
221 - }
222 - }
223 - ],
224 - quickReplies: [{
225 - action: "block",
226 - label: "MBTI 테스트 다시하기",
227 - message: "MBTI 테스트 다시하기",
228 - blockId : "628b8005055a574d7df54466"
229 - }]
230 - }
231 - }
232 - res.status(200).send(responseBody);
233 -});
234 -
235 app.listen((process.env.PORT || 3000), function() { 112 app.listen((process.env.PORT || 3000), function() {
236 console.log('Example skill server listening on port 3000!'); 113 console.log('Example skill server listening on port 3000!');
237 }); 114 });
...\ No newline at end of file ...\ No newline at end of file
......