Showing
1 changed file
with
62 additions
and
2 deletions
1 | const express = require('express'); | 1 | const express = require('express'); |
2 | const app = express(); | 2 | const app = express(); |
3 | - | ||
4 | const bodyParser = require('body-parser'); | 3 | const bodyParser = require('body-parser'); |
5 | 4 | ||
6 | const apiRouter = express.Router(); | 5 | const apiRouter = express.Router(); |
... | @@ -12,6 +11,10 @@ app.use(bodyParser.urlencoded({ | ... | @@ -12,6 +11,10 @@ app.use(bodyParser.urlencoded({ |
12 | 11 | ||
13 | app.use('/api', apiRouter); | 12 | app.use('/api', apiRouter); |
14 | 13 | ||
14 | +// NAVER SEARCH API | ||
15 | +const CLIENT_ID = 'fhcqiYQacNyJGILdJBzL'; | ||
16 | +const CLIENT_SECRET = 'dmxhW0M_NA'; | ||
17 | + | ||
15 | let userDB = new Array(); | 18 | let userDB = new Array(); |
16 | 19 | ||
17 | apiRouter.post('/sayHello', function(req, res) { | 20 | apiRouter.post('/sayHello', function(req, res) { |
... | @@ -883,7 +886,14 @@ apiRouter.post('/result', (req, res) => { | ... | @@ -883,7 +886,14 @@ apiRouter.post('/result', (req, res) => { |
883 | label: "자세한 결과 보기", | 886 | label: "자세한 결과 보기", |
884 | message: "자세한 결과 보기", | 887 | message: "자세한 결과 보기", |
885 | blockId: "6297bc58ab89e678ee86b33a" | 888 | blockId: "6297bc58ab89e678ee86b33a" |
886 | - }] | 889 | + }, |
890 | + { | ||
891 | + action: "block", | ||
892 | + label: "내 MBTI 특징은?", | ||
893 | + message: "내 MBTI 특징은?", | ||
894 | + blockId: "6299ef8aab89e678ee86da0d" | ||
895 | + } | ||
896 | + ] | ||
887 | } | 897 | } |
888 | } | 898 | } |
889 | res.status(200).send(responseBody); | 899 | res.status(200).send(responseBody); |
... | @@ -995,6 +1005,56 @@ function count_mbti(item_list, mbti_ch) { | ... | @@ -995,6 +1005,56 @@ function count_mbti(item_list, mbti_ch) { |
995 | return result; | 1005 | return result; |
996 | } | 1006 | } |
997 | 1007 | ||
1008 | +apiRouter.post('/searchmbti', (req, res) => { | ||
1009 | + var userId = req.body.userRequest.user.id; | ||
1010 | + var userMbti = userDB[userId][4]; | ||
1011 | + var api_url = 'https://openapi.naver.com/v1/search/blog?query='+ encodeURI(userMbti + '특징'); | ||
1012 | + var request = require('request'); | ||
1013 | + console.log(api_url); | ||
1014 | + | ||
1015 | + var options = { | ||
1016 | + url: api_url, | ||
1017 | + headers: {'X-Naver-Client-Id':CLIENT_ID, 'X-Naver-Client-Secret': CLIENT_SECRET} | ||
1018 | + }; | ||
1019 | + | ||
1020 | + request.get(options, function (error, response, body) { | ||
1021 | + if (!error && response.statusCode == 200) { | ||
1022 | + var result = JSON.parse(body); | ||
1023 | + console.log(result.items); | ||
1024 | + const responseBody = { | ||
1025 | + version: "2.0", | ||
1026 | + template: { | ||
1027 | + outputs: [ | ||
1028 | + { | ||
1029 | + simpleText: { | ||
1030 | + text: result.items[0].link | ||
1031 | + } | ||
1032 | + } | ||
1033 | + ], | ||
1034 | + quickReplies: [{ | ||
1035 | + action: "block", | ||
1036 | + label: "MBTI 테스트 다시하기", | ||
1037 | + message: "MBTI 테스트 다시하기", | ||
1038 | + blockId : "6297b10d5ceed96c38544a06" | ||
1039 | + }, | ||
1040 | + { | ||
1041 | + action: "block", | ||
1042 | + label: "자세한 결과 보기", | ||
1043 | + message: "자세한 결과 보기", | ||
1044 | + blockId: "6297bc58ab89e678ee86b33a" | ||
1045 | + } | ||
1046 | + ] | ||
1047 | + } | ||
1048 | + } | ||
1049 | + res.status(200).send(responseBody); | ||
1050 | + } else { | ||
1051 | + res.status(response.statusCode).end(); | ||
1052 | + console.log('error = ' + response.statusCode); | ||
1053 | + } | ||
1054 | + }); | ||
1055 | + | ||
1056 | +}); | ||
1057 | + | ||
998 | app.listen((process.env.PORT || 3000), function() { | 1058 | app.listen((process.env.PORT || 3000), function() { |
999 | console.log('Example skill server listening on port 3000!'); | 1059 | console.log('Example skill server listening on port 3000!'); |
1000 | }); | 1060 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment