공정훈

Update app.js Ver.5

...@@ -17,6 +17,25 @@ const CLIENT_SECRET = 'dmxhW0M_NA'; ...@@ -17,6 +17,25 @@ const CLIENT_SECRET = 'dmxhW0M_NA';
17 17
18 let userDB = new Array(); 18 let userDB = new Array();
19 19
20 +
21 +const mbtiDB= new Array();
22 +mbtiDB[0] = ['ISTP', 'https://ifh.cc/g/ac3LWB.jpg'];
23 +mbtiDB[1] = ['ISTJ', 'https://ifh.cc/g/VRFgFq.jpg'];
24 +mbtiDB[2] = ['ISFP', 'https://ifh.cc/g/svsfk3.jpg'];
25 +mbtiDB[3] = ['ISFJ', 'https://ifh.cc/g/5LMJjh.jpg'];
26 +mbtiDB[4] = ['INTP', 'https://ifh.cc/g/9HmqMW.jpg'];
27 +mbtiDB[5] = ['INTJ', 'https://ifh.cc/g/sGrpDH.jpg'];
28 +mbtiDB[6] = ['INFP','https://ifh.cc/g/0cK5Rq.jpg'];
29 +mbtiDB[7] = ['INFJ', 'https://ifh.cc/g/34opTR.jpg'];
30 +mbtiDB[8] = ['ESTP', 'https://ifh.cc/g/6wHm7a.jpg'];
31 +mbtiDB[9] = ['ESTJ', 'https://ifh.cc/g/fVGAnT.jpg'];
32 +mbtiDB[10] = ['ESFP', 'https://ifh.cc/g/0S0gk9.jpg'];
33 +mbtiDB[11] = ['ESFJ', 'https://ifh.cc/g/Zh8mVx.jpg'];
34 +mbtiDB[12] = ['ENTP', 'https://ifh.cc/g/opCw8r.jpg'];
35 +mbtiDB[13] = ['ENTJ', 'https://ifh.cc/g/PvlQyS.jpg'];
36 +mbtiDB[14] = ['ENFP', 'https://ifh.cc/g/AArxoZ.jpg'];
37 +mbtiDB[15] = ['ENFJ', 'https://ifh.cc/g/c6GRH1.jpg'];
38 +
20 apiRouter.post('/sayHello', function(req, res) { 39 apiRouter.post('/sayHello', function(req, res) {
21 const responseBody = { 40 const responseBody = {
22 version: "2.0", 41 version: "2.0",
...@@ -865,39 +884,45 @@ apiRouter.post('/result', (req, res) => { ...@@ -865,39 +884,45 @@ apiRouter.post('/result', (req, res) => {
865 userDB[userId][3] += mbti; 884 userDB[userId][3] += mbti;
866 console.log(userDB[userId]); 885 console.log(userDB[userId]);
867 analysis_mbti(userDB[userId]); 886 analysis_mbti(userDB[userId]);
887 + var imageurl = url(userDB[userId]);
868 const responseBody = { 888 const responseBody = {
869 version: "2.0", 889 version: "2.0",
870 template: { 890 template: {
871 - outputs: [ 891 + outputs: [
872 - { 892 + {
873 - simpleText: { 893 + "basicCard": {
874 - text: "당신의 MBTI는 : "+userDB[userId][4] 894 + "title": "당신의 MBTI는 : "+userDB[userId][4],
875 - } 895 + "thumbnail": {
896 + "imageUrl": imageurl
897 + },
898 + "buttons": [
899 + {
900 + action: "block",
901 + label: "자세한 결과 보기",
902 + message: "자세한 결과 보기",
903 + blockId: "6297bc58ab89e678ee86b33a"
904 + },
905 + {
906 + action: "block",
907 + label: "내 MBTI 특징은?",
908 + message: "내 MBTI 특징은?",
909 + blockId: "629ced645ceed96c38548222"
910 + },
911 + {
912 + action: "block",
913 + label: "내 MBTI 관련 영상보기",
914 + message: "내 MBTI 관련 영상보기",
915 + blockId: "629b6af95ceed96c38547c19"
916 + }
917 + ]
876 } 918 }
919 + }
877 ], 920 ],
878 quickReplies: [{ 921 quickReplies: [{
879 action: "block", 922 action: "block",
880 label: "MBTI 테스트 다시하기", 923 label: "MBTI 테스트 다시하기",
881 message: "MBTI 테스트 다시하기", 924 message: "MBTI 테스트 다시하기",
882 blockId : "6297b10d5ceed96c38544a06" 925 blockId : "6297b10d5ceed96c38544a06"
883 - },
884 - {
885 - action: "block",
886 - label: "자세한 결과 보기",
887 - message: "자세한 결과 보기",
888 - blockId: "6297bc58ab89e678ee86b33a"
889 - },
890 - {
891 - action: "block",
892 - label: "내 MBTI 특징은?",
893 - message: "내 MBTI 특징은?",
894 - blockId: "629ced645ceed96c38548222"
895 - },
896 - {
897 - action: "block",
898 - label: "내 MBTI 관련 영상 보러 가기",
899 - message: "내 MBTI 관련 영상 보러 가기",
900 - blockId: "629b6af95ceed96c38547c19"
901 } 926 }
902 ] 927 ]
903 } 928 }
...@@ -1011,56 +1036,6 @@ function count_mbti(item_list, mbti_ch) { ...@@ -1011,56 +1036,6 @@ function count_mbti(item_list, mbti_ch) {
1011 return result; 1036 return result;
1012 } 1037 }
1013 1038
1014 -apiRouter.post('/searchmbti', (req, res) => {
1015 - var userId = req.body.userRequest.user.id;
1016 - var userMbti = userDB[userId][4];
1017 - var api_url = 'https://openapi.naver.com/v1/search/blog?query='+ encodeURI(userMbti + '특징');
1018 - var request = require('request');
1019 - console.log(api_url);
1020 -
1021 - var options = {
1022 - url: api_url,
1023 - headers: {'X-Naver-Client-Id':CLIENT_ID, 'X-Naver-Client-Secret': CLIENT_SECRET}
1024 - };
1025 -
1026 - request.get(options, function (error, response, body) {
1027 - if (!error && response.statusCode == 200) {
1028 - var result = JSON.parse(body);
1029 - console.log(result.items);
1030 - const responseBody = {
1031 - version: "2.0",
1032 - template: {
1033 - outputs: [
1034 - {
1035 - simpleText: {
1036 - text: result.items[0].link
1037 - }
1038 - }
1039 - ],
1040 - quickReplies: [{
1041 - action: "block",
1042 - label: "MBTI 테스트 다시하기",
1043 - message: "MBTI 테스트 다시하기",
1044 - blockId : "6297b10d5ceed96c38544a06"
1045 - },
1046 - {
1047 - action: "block",
1048 - label: "자세한 결과 보기",
1049 - message: "자세한 결과 보기",
1050 - blockId: "6297bc58ab89e678ee86b33a"
1051 - }
1052 - ]
1053 - }
1054 - }
1055 - res.status(200).send(responseBody);
1056 - } else {
1057 - res.status(response.statusCode).end();
1058 - console.log('error = ' + response.statusCode);
1059 - }
1060 - });
1061 -
1062 -});
1063 -
1064 apiRouter.post('/mbtivideo', (req, res) => { 1039 apiRouter.post('/mbtivideo', (req, res) => {
1065 var userId = req.body.userRequest.user.id; 1040 var userId = req.body.userRequest.user.id;
1066 var userMbti = userDB[userId][4]; 1041 var userMbti = userDB[userId][4];
...@@ -1144,12 +1119,11 @@ apiRouter.post('/mbtivideo', (req, res) => { ...@@ -1144,12 +1119,11 @@ apiRouter.post('/mbtivideo', (req, res) => {
1144 }); 1119 });
1145 1120
1146 apiRouter.post('/searchMBTI', (req, res) => { 1121 apiRouter.post('/searchMBTI', (req, res) => {
1147 - var imageurl=""
1148 var userId = req.body.userRequest.user.id; 1122 var userId = req.body.userRequest.user.id;
1149 var userMbti = userDB[userId][4]; 1123 var userMbti = userDB[userId][4];
1150 var api_url = 'https://openapi.naver.com/v1/search/blog?query='+ encodeURI(userMbti + '특징'); 1124 var api_url = 'https://openapi.naver.com/v1/search/blog?query='+ encodeURI(userMbti + '특징');
1151 var request = require('request'); 1125 var request = require('request');
1152 - url(userDB); 1126 + var imagerul = url(userDB[userId]);
1153 console.log(api_url); 1127 console.log(api_url);
1154 1128
1155 var options = { 1129 var options = {
...@@ -1160,26 +1134,40 @@ apiRouter.post('/searchMBTI', (req, res) => { ...@@ -1160,26 +1134,40 @@ apiRouter.post('/searchMBTI', (req, res) => {
1160 request.get(options, function (error, response, body) { 1134 request.get(options, function (error, response, body) {
1161 if (!error && response.statusCode == 200) { 1135 if (!error && response.statusCode == 200) {
1162 var result = JSON.parse(body); 1136 var result = JSON.parse(body);
1163 - console.log(result.items); 1137 + console.log(result.items, "i'm version2");
1164 const responseBody = { 1138 const responseBody = {
1165 version: "2.0", 1139 version: "2.0",
1166 template: { 1140 template: {
1167 outputs: [ 1141 outputs: [
1168 { 1142 {
1169 - "basicCard": { 1143 + "listCard" : {
1170 - "title": userMbti, 1144 + "header": {
1171 - "description": userMbti+"의 특징은?", 1145 + "title":userMbti+" 특징은?"
1172 - "thumbnail": {
1173 - "imageUrl": imageurl
1174 }, 1146 },
1175 - "buttons": [ 1147 + "items": [
1176 - { 1148 + {
1177 - "action": "webLink", 1149 + "title": result.items[0].title.replace(/<b>/g, '').replace(/<\/b>/g, ''),
1178 - "label": "알아보기", 1150 + "description": result.items[0].description,
1179 - "webLinkUrl": result.items[0].link 1151 + "link":{
1180 - } 1152 + "web": result.items[0].link
1153 + }
1154 + },
1155 + {
1156 + "title": result.items[1].title.replace(/<b>/g, '').replace(/<\/b>/g, ''),
1157 + "description": result.items[1].description,
1158 + "link":{
1159 + "web": result.items[1].link
1160 + }
1161 + },
1162 + {
1163 + "title": result.items[2].title.replace(/<b>/g, '').replace(/<\/b>/g, ''),
1164 + "description": result.items[2].description,
1165 + "link":{
1166 + "web": result.items[2].link
1167 + }
1168 + }
1181 ] 1169 ]
1182 - } 1170 + }
1183 } 1171 }
1184 ], 1172 ],
1185 quickReplies: [{ 1173 quickReplies: [{
...@@ -1193,6 +1181,12 @@ apiRouter.post('/searchMBTI', (req, res) => { ...@@ -1193,6 +1181,12 @@ apiRouter.post('/searchMBTI', (req, res) => {
1193 label: "자세한 결과 보기", 1181 label: "자세한 결과 보기",
1194 message: "자세한 결과 보기", 1182 message: "자세한 결과 보기",
1195 blockId: "6297bc58ab89e678ee86b33a" 1183 blockId: "6297bc58ab89e678ee86b33a"
1184 + },
1185 + {
1186 + action: "block",
1187 + label: "내 MBTI 관련 영상보기",
1188 + message: "내 MBTI 관련 영상보기",
1189 + blockId: "629b6af95ceed96c38547c19"
1196 } 1190 }
1197 ] 1191 ]
1198 } 1192 }
...@@ -1207,32 +1201,12 @@ apiRouter.post('/searchMBTI', (req, res) => { ...@@ -1207,32 +1201,12 @@ apiRouter.post('/searchMBTI', (req, res) => {
1207 }); 1201 });
1208 1202
1209 function url(user){ 1203 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++){ 1204 for(let i=0; i<16;i++){
1232 - if(user[userId][4]==mbtiDB[i]){ 1205 + if(user[4]==mbtiDB[i][0]){
1233 - imageurl=mbtiDB[i][0] 1206 + imageurl=mbtiDB[i][1];
1234 } 1207 }
1235 } 1208 }
1209 + return imageurl;
1236 } 1210 }
1237 1211
1238 app.listen((process.env.PORT || 3000), function() { 1212 app.listen((process.env.PORT || 3000), function() {
......
This diff is collapsed. Click to expand it.
1 { 1 {
2 "dependencies": { 2 "dependencies": {
3 - "express": "^4.18.1" 3 + "express": "^4.18.1",
4 + "request": "^2.88.2"
4 } 5 }
5 } 6 }
......