Showing
1 changed file
with
92 additions
and
0 deletions
... | @@ -1143,6 +1143,98 @@ apiRouter.post('/mbtivideo', (req, res) => { | ... | @@ -1143,6 +1143,98 @@ apiRouter.post('/mbtivideo', (req, res) => { |
1143 | 1143 | ||
1144 | }); | 1144 | }); |
1145 | 1145 | ||
1146 | +apiRouter.post('/searchMBTI', (req, res) => { | ||
1147 | + var imageurl="" | ||
1148 | + var userId = req.body.userRequest.user.id; | ||
1149 | + var userMbti = userDB[userId][4]; | ||
1150 | + var api_url = 'https://openapi.naver.com/v1/search/blog?query='+ encodeURI(userMbti + '특징'); | ||
1151 | + var request = require('request'); | ||
1152 | + url(userDB); | ||
1153 | + console.log(api_url); | ||
1154 | + | ||
1155 | + var options = { | ||
1156 | + url: api_url, | ||
1157 | + headers: {'X-Naver-Client-Id':CLIENT_ID, 'X-Naver-Client-Secret': CLIENT_SECRET} | ||
1158 | + }; | ||
1159 | + | ||
1160 | + request.get(options, function (error, response, body) { | ||
1161 | + if (!error && response.statusCode == 200) { | ||
1162 | + var result = JSON.parse(body); | ||
1163 | + console.log(result.items); | ||
1164 | + const responseBody = { | ||
1165 | + version: "2.0", | ||
1166 | + template: { | ||
1167 | + outputs: [ | ||
1168 | + { | ||
1169 | + "basicCard": { | ||
1170 | + "title": userMbti, | ||
1171 | + "description": userMbti+"의 특징은?", | ||
1172 | + "thumbnail": { | ||
1173 | + "imageUrl": imageurl | ||
1174 | + }, | ||
1175 | + "buttons": [ | ||
1176 | + { | ||
1177 | + "action": "webLink", | ||
1178 | + "label": "알아보기", | ||
1179 | + "webLinkUrl": result.items[0].link | ||
1180 | + } | ||
1181 | + ] | ||
1182 | + } | ||
1183 | + } | ||
1184 | + ], | ||
1185 | + quickReplies: [{ | ||
1186 | + action: "block", | ||
1187 | + label: "MBTI 테스트 다시하기", | ||
1188 | + message: "MBTI 테스트 다시하기", | ||
1189 | + blockId : "6297b10d5ceed96c38544a06" | ||
1190 | + }, | ||
1191 | + { | ||
1192 | + action: "block", | ||
1193 | + label: "자세한 결과 보기", | ||
1194 | + message: "자세한 결과 보기", | ||
1195 | + blockId: "6297bc58ab89e678ee86b33a" | ||
1196 | + } | ||
1197 | + ] | ||
1198 | + } | ||
1199 | + } | ||
1200 | + res.status(200).send(responseBody); | ||
1201 | + } else { | ||
1202 | + res.status(response.statusCode).end(); | ||
1203 | + console.log('error = ' + response.statusCode); | ||
1204 | + } | ||
1205 | + }); | ||
1206 | + | ||
1207 | +}); | ||
1208 | + | ||
1209 | +function url(user){ | ||
1210 | + | ||
1211 | + let mbtiDB = new Array(); | ||
1212 | + | ||
1213 | +mbtiDB=['ISTP','ISTJ','ISFP','ISFJ','INTP','INTJ','INFP','INFJ','ESTP','ESTJ','ESFP','ESFJ','ENTP','ENTJ','ENFP','ENFJ'] | ||
1214 | +mbtiDB[0][0]='https://ifh.cc/g/ac3LWB.jpg'; | ||
1215 | +mbtiDB[1][0]='https://ifh.cc/g/VRFgFq.jpg'; | ||
1216 | +mbtiDB[2][0]='https://ifh.cc/g/svsfk3.jpg'; | ||
1217 | +mbtiDB[3][0]='https://ifh.cc/g/5LMJjh.jpg'; | ||
1218 | +mbtiDB[4][0]='https://ifh.cc/g/9HmqMW.jpg'; | ||
1219 | +mbtiDB[5][0]='https://ifh.cc/g/sGrpDH.jpg'; | ||
1220 | +mbtiDB[6][0]='https://ifh.cc/g/0cK5Rq.jpg'; | ||
1221 | +mbtiDB[7][0]='https://ifh.cc/g/34opTR.jpg'; | ||
1222 | +mbtiDB[8][0]='https://ifh.cc/g/6wHm7a.jpg'; | ||
1223 | +mbtiDB[9][0]='https://ifh.cc/g/fVGAnT.jpg'; | ||
1224 | +mbtiDB[10][0]='https://ifh.cc/g/0S0gk9.jpg'; | ||
1225 | +mbtiDB[11][0]='https://ifh.cc/g/Zh8mVx.jpg'; | ||
1226 | +mbtiDB[12][0]='https://ifh.cc/g/opCw8r.jpg'; | ||
1227 | +mbtiDB[13][0]='https://ifh.cc/g/PvlQyS.jpg'; | ||
1228 | +mbtiDB[14][0]='https://ifh.cc/g/AArxoZ.jpg'; | ||
1229 | +mbtiDB[15][0]='https://ifh.cc/g/c6GRH1.jpg'; | ||
1230 | + | ||
1231 | + for(let i=0; i<16;i++){ | ||
1232 | + if(user[userId][4]==mbtiDB[i]){ | ||
1233 | + imageurl=mbtiDB[i][0] | ||
1234 | + } | ||
1235 | + } | ||
1236 | +} | ||
1237 | + | ||
1146 | app.listen((process.env.PORT || 3000), function() { | 1238 | app.listen((process.env.PORT || 3000), function() { |
1147 | console.log('Example skill server listening on port 3000!'); | 1239 | console.log('Example skill server listening on port 3000!'); |
1148 | }); | 1240 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment