Minkyung Ko

Add mbti video search

...@@ -892,6 +892,12 @@ apiRouter.post('/result', (req, res) => { ...@@ -892,6 +892,12 @@ apiRouter.post('/result', (req, res) => {
892 label: "내 MBTI 특징은?", 892 label: "내 MBTI 특징은?",
893 message: "내 MBTI 특징은?", 893 message: "내 MBTI 특징은?",
894 blockId: "6299ef8aab89e678ee86da0d" 894 blockId: "6299ef8aab89e678ee86da0d"
895 + },
896 + {
897 + action: "block",
898 + label: "내 MBTI 관련 영상 보러 가기",
899 + message: "내 MBTI 관련 영상 보러 가기",
900 + blockId: "629b6af95ceed96c38547c19"
895 } 901 }
896 ] 902 ]
897 } 903 }
...@@ -1055,6 +1061,88 @@ apiRouter.post('/searchmbti', (req, res) => { ...@@ -1055,6 +1061,88 @@ apiRouter.post('/searchmbti', (req, res) => {
1055 1061
1056 }); 1062 });
1057 1063
1064 +apiRouter.post('/mbtivideo', (req, res) => {
1065 + var userId = req.body.userRequest.user.id;
1066 + var userMbti = userDB[userId][4];
1067 + var api_url = 'https://dapi.kakao.com/v2/search/vclip?query=' + userMbti;
1068 + var request = require('request');
1069 + console.log(api_url);
1070 +
1071 + var options = {
1072 + url: api_url,
1073 + method: 'GET',
1074 + headers: {
1075 + 'Authorization': 'KakaoAK 45ad937a71c8578ec94f9b5c6c58838b'
1076 + },
1077 + encoding: 'UTF-8',
1078 + }
1079 +
1080 + request(options, function (error, response, body) {
1081 + if (!error && response.statusCode == 200) {
1082 + var result = JSON.parse(body);
1083 + console.log(result.documents);
1084 + const responseBody = {
1085 + version: "2.0",
1086 + template: {
1087 + outputs: [
1088 + {
1089 + "listCard" : {
1090 + "header": {
1091 + "title":userMbti+" 관련 영상입니다."
1092 + },
1093 + "items": [
1094 + {
1095 + "title": result.documents[0].title,
1096 + "description": result.documents[0].author,
1097 + "imageUrl": result.documents[0].thumbnail,
1098 + "link":{
1099 + "web": result.documents[0].url
1100 + }
1101 + },
1102 + {
1103 + "title": result.documents[1].title,
1104 + "description": result.documents[1].author,
1105 + "imageUrl": result.documents[1].thumbnail,
1106 + "link":{
1107 + "web": result.documents[1].url
1108 + }
1109 + },
1110 + {
1111 + "title": result.documents[2].title,
1112 + "description": result.documents[2].author,
1113 + "imageUrl": result.documents[2].thumbnail,
1114 + "link":{
1115 + "web": result.documents[2].url
1116 + }
1117 + }
1118 + ]
1119 + }
1120 + }
1121 + ],
1122 + quickReplies: [{
1123 + action: "block",
1124 + label: "MBTI 테스트 다시하기",
1125 + message: "MBTI 테스트 다시하기",
1126 + blockId : "6297b10d5ceed96c38544a06"
1127 + },
1128 + {
1129 + action: "block",
1130 + label: "자세한 결과 보기",
1131 + message: "자세한 결과 보기",
1132 + blockId: "6297bc58ab89e678ee86b33a"
1133 + }
1134 + ]
1135 + }
1136 + }
1137 + res.status(200).send(responseBody);
1138 + } else {
1139 + res.status(response.statusCode).end();
1140 + console.log('error = ' + response.statusCode);
1141 + }
1142 + });
1143 +
1144 +});
1145 +
1058 app.listen((process.env.PORT || 3000), function() { 1146 app.listen((process.env.PORT || 3000), function() {
1059 console.log('Example skill server listening on port 3000!'); 1147 console.log('Example skill server listening on port 3000!');
1060 }); 1148 });
...\ No newline at end of file ...\ No newline at end of file
......