Merge remote-tracking branch 'origin/feature/mbti_list'
Showing
1 changed file
with
169 additions
and
0 deletions
... | @@ -13,6 +13,25 @@ app.use(bodyParser.urlencoded({ | ... | @@ -13,6 +13,25 @@ app.use(bodyParser.urlencoded({ |
13 | 13 | ||
14 | app.use('/api', apiRouter); | 14 | app.use('/api', apiRouter); |
15 | 15 | ||
16 | +apiRouter.post("/blockId", function(req, res) { | ||
17 | + const userRequest = req.body.userRequest; | ||
18 | + const blockId = userRequest.block.id; | ||
19 | + | ||
20 | + return res.send({ | ||
21 | + version: "2.0", | ||
22 | + template: { | ||
23 | + outputs: [ | ||
24 | + { | ||
25 | + "basicCard": { | ||
26 | + "title": "블록ID 입니다", | ||
27 | + "description": blockId | ||
28 | + } | ||
29 | + } | ||
30 | + ] | ||
31 | + } | ||
32 | + }); | ||
33 | +}); | ||
34 | + | ||
16 | apiRouter.post('/sayHello', function(req, res) { | 35 | apiRouter.post('/sayHello', function(req, res) { |
17 | const responseBody = { | 36 | const responseBody = { |
18 | version: "2.0", | 37 | version: "2.0", |
... | @@ -40,6 +59,156 @@ apiRouter.post('/sayHello', function(req, res) { | ... | @@ -40,6 +59,156 @@ apiRouter.post('/sayHello', function(req, res) { |
40 | res.status(200).send(responseBody); | 59 | res.status(200).send(responseBody); |
41 | }); | 60 | }); |
42 | 61 | ||
62 | +var mbtilist = { | ||
63 | + I: false, | ||
64 | + E: false, | ||
65 | + S: false, | ||
66 | + N: false, | ||
67 | + T: false, | ||
68 | + F: false, | ||
69 | + P: false, | ||
70 | + J: false | ||
71 | +}; | ||
72 | + | ||
73 | +var userDB = {}; | ||
74 | + | ||
75 | +apiRouter.post("/add", function(req, res) { | ||
76 | + const userRequest = req.body.userRequest; | ||
77 | + const userId = userRequest.user.id; | ||
78 | + const usermbti = userRequest.utterance; | ||
79 | + | ||
80 | + if (!userDB[userId]) { | ||
81 | + userDB[userId] = { ...mbtilist }; | ||
82 | + } | ||
83 | + | ||
84 | + if (usermbti in mbtilist) { | ||
85 | + userDB[userId][usermbti] = true; | ||
86 | + } | ||
87 | + | ||
88 | + return res.send({ | ||
89 | + version: "2.0", | ||
90 | + template: { | ||
91 | + outputs: [ | ||
92 | + { | ||
93 | + basicCard: { | ||
94 | + description: "추가 되었습니다", | ||
95 | + buttons: [ | ||
96 | + { | ||
97 | + action: "message", | ||
98 | + label: "내 mbti 목록", | ||
99 | + messageText: "내 mbti 목록" | ||
100 | + }, | ||
101 | + { | ||
102 | + action: "message", | ||
103 | + label: "mbti 추가", | ||
104 | + messageText: "mbti 추가" | ||
105 | + } | ||
106 | + ] | ||
107 | + } | ||
108 | + } | ||
109 | + ] | ||
110 | + } | ||
111 | + }); | ||
112 | +}); | ||
113 | + | ||
114 | +apiRouter.post("/form", function(req,res) { | ||
115 | + const userRequest = req.body.userRequest; | ||
116 | + const userId = userRequest.user.id; | ||
117 | + let mbti = []; | ||
118 | + | ||
119 | + if (!userDB[userId]) { | ||
120 | + mbti = Object.keys(mbtilist).map(f => { | ||
121 | + return { | ||
122 | + action: "block", | ||
123 | + label: f, | ||
124 | + blockId: "62903faf7befc3101c3be587" | ||
125 | + }; | ||
126 | + }); | ||
127 | + } else { | ||
128 | + mbti = Object.keys(userDB[userId]) | ||
129 | + .filter(f => { | ||
130 | + return userDB[userId][f] === false; | ||
131 | + }) | ||
132 | + .map(f => { | ||
133 | + return { | ||
134 | + action: "block", | ||
135 | + label: f, | ||
136 | + blockId: "62903faf7befc3101c3be587" | ||
137 | + }; | ||
138 | + }); | ||
139 | + } | ||
140 | + | ||
141 | + return res.send({ | ||
142 | + version: "2.0", | ||
143 | + template: { | ||
144 | + outputs: [ | ||
145 | + { | ||
146 | + simpleText: { | ||
147 | + text: "추가할 mbti를 선택해 주세요" | ||
148 | + } | ||
149 | + } | ||
150 | + ], | ||
151 | + quickReplies: mbti | ||
152 | + } | ||
153 | + }); | ||
154 | +}); | ||
155 | + | ||
156 | +apiRouter.post("/list", function(req, res) { | ||
157 | + const userRequest = req.body.userRequest; | ||
158 | + const userId = userRequest.user.id; | ||
159 | + let mymbti = []; | ||
160 | + | ||
161 | + if (userDB[userId]) { | ||
162 | + mymbti = Object.keys(userDB[userId]).filter(f => { | ||
163 | + return userDB[userId][f] === true; | ||
164 | + }); | ||
165 | + } | ||
166 | + | ||
167 | + if (mymbti.length <= 0) { | ||
168 | + return res.send({ | ||
169 | + version: "2.0", | ||
170 | + template: { | ||
171 | + outputs: [ | ||
172 | + { | ||
173 | + basicCard: { | ||
174 | + description: "등록된 mbti가 없습니다", | ||
175 | + buttons: [ | ||
176 | + { | ||
177 | + action: "message", | ||
178 | + label: "mbti 추가", | ||
179 | + messageText: "mbti 추가" | ||
180 | + } | ||
181 | + ] | ||
182 | + } | ||
183 | + } | ||
184 | + ] | ||
185 | + } | ||
186 | + }); | ||
187 | + } else { | ||
188 | + return res.send({ | ||
189 | + version: "2.0", | ||
190 | + template: { | ||
191 | + outputs: [ | ||
192 | + { | ||
193 | + basicCard: { | ||
194 | + description: `현재 나의 mbti는 ${mymbti | ||
195 | + .map(f => `[${f}]`) | ||
196 | + .join(", ")} 입니다`, | ||
197 | + buttons: [ | ||
198 | + { | ||
199 | + action: "message", | ||
200 | + label: "mbti 추가", | ||
201 | + messageText: "mtbi 추가" | ||
202 | + } | ||
203 | + ] | ||
204 | + } | ||
205 | + } | ||
206 | + ] | ||
207 | + } | ||
208 | + }); | ||
209 | + } | ||
210 | +}); | ||
211 | + | ||
43 | apiRouter.post('/question1', (req, res) => { | 212 | apiRouter.post('/question1', (req, res) => { |
44 | var mesg = req.body.userRequest; | 213 | var mesg = req.body.userRequest; |
45 | console.log('[q1:user message] ', mesg); | 214 | console.log('[q1:user message] ', mesg); | ... | ... |
-
Please register or login to post a comment