Minkyung Ko

Save mbti list feature added

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",
...@@ -34,6 +53,156 @@ apiRouter.post('/sayHello', function(req, res) { ...@@ -34,6 +53,156 @@ apiRouter.post('/sayHello', function(req, res) {
34 res.status(200).send(responseBody); 53 res.status(200).send(responseBody);
35 }); 54 });
36 55
56 +var mbtilist = {
57 + I: false,
58 + E: false,
59 + S: false,
60 + N: false,
61 + T: false,
62 + F: false,
63 + P: false,
64 + J: false
65 +};
66 +
67 +var userDB = {};
68 +
69 +apiRouter.post("/add", function(req, res) {
70 + const userRequest = req.body.userRequest;
71 + const userId = userRequest.user.id;
72 + const usermbti = userRequest.utterance;
73 +
74 + if (!userDB[userId]) {
75 + userDB[userId] = { ...mbtilist };
76 + }
77 +
78 + if (usermbti in mbtilist) {
79 + userDB[userId][usermbti] = true;
80 + }
81 +
82 + return res.send({
83 + version: "2.0",
84 + template: {
85 + outputs: [
86 + {
87 + basicCard: {
88 + description: "추가 되었습니다",
89 + buttons: [
90 + {
91 + action: "message",
92 + label: "내 mbti 목록",
93 + messageText: "내 mbti 목록"
94 + },
95 + {
96 + action: "message",
97 + label: "mbti 추가",
98 + messageText: "mbti 추가"
99 + }
100 + ]
101 + }
102 + }
103 + ]
104 + }
105 + });
106 +});
107 +
108 +apiRouter.post("/form", function(req,res) {
109 + const userRequest = req.body.userRequest;
110 + const userId = userRequest.user.id;
111 + let mbti = [];
112 +
113 + if (!userDB[userId]) {
114 + mbti = Object.keys(mbtilist).map(f => {
115 + return {
116 + action: "block",
117 + label: f,
118 + blockId: "62903faf7befc3101c3be587"
119 + };
120 + });
121 + } else {
122 + mbti = Object.keys(userDB[userId])
123 + .filter(f => {
124 + return userDB[userId][f] === false;
125 + })
126 + .map(f => {
127 + return {
128 + action: "block",
129 + label: f,
130 + blockId: "62903faf7befc3101c3be587"
131 + };
132 + });
133 + }
134 +
135 + return res.send({
136 + version: "2.0",
137 + template: {
138 + outputs: [
139 + {
140 + simpleText: {
141 + text: "추가할 mbti를 선택해 주세요"
142 + }
143 + }
144 + ],
145 + quickReplies: mbti
146 + }
147 + });
148 +});
149 +
150 +apiRouter.post("/list", function(req, res) {
151 + const userRequest = req.body.userRequest;
152 + const userId = userRequest.user.id;
153 + let mymbti = [];
154 +
155 + if (userDB[userId]) {
156 + mymbti = Object.keys(userDB[userId]).filter(f => {
157 + return userDB[userId][f] === true;
158 + });
159 + }
160 +
161 + if (mymbti.length <= 0) {
162 + return res.send({
163 + version: "2.0",
164 + template: {
165 + outputs: [
166 + {
167 + basicCard: {
168 + description: "등록된 mbti가 없습니다",
169 + buttons: [
170 + {
171 + action: "message",
172 + label: "mbti 추가",
173 + messageText: "mbti 추가"
174 + }
175 + ]
176 + }
177 + }
178 + ]
179 + }
180 + });
181 + } else {
182 + return res.send({
183 + version: "2.0",
184 + template: {
185 + outputs: [
186 + {
187 + basicCard: {
188 + description: `현재 나의 mbti는 ${mymbti
189 + .map(f => `[${f}]`)
190 + .join(", ")} 입니다`,
191 + buttons: [
192 + {
193 + action: "message",
194 + label: "mbti 추가",
195 + messageText: "mtbi 추가"
196 + }
197 + ]
198 + }
199 + }
200 + ]
201 + }
202 + });
203 + }
204 +});
205 +
37 apiRouter.post('/question1', (req, res) => { 206 apiRouter.post('/question1', (req, res) => {
38 const responseBody = { 207 const responseBody = {
39 version: "2.0", 208 version: "2.0",
......