Showing
1 changed file
with
46 additions
and
1 deletions
... | @@ -8,6 +8,9 @@ const HTTPS = require('https'); | ... | @@ -8,6 +8,9 @@ const HTTPS = require('https'); |
8 | const domain = "도메인 변경" | 8 | const domain = "도메인 변경" |
9 | const sslport = 23023; | 9 | const sslport = 23023; |
10 | 10 | ||
11 | +var client_id = 'YOUR_CLIENT_ID'; | ||
12 | +var client_secret = 'YOUR_CLIENT_SECRET'; | ||
13 | + | ||
11 | const bodyParser = require('body-parser'); | 14 | const bodyParser = require('body-parser'); |
12 | var app = express(); | 15 | var app = express(); |
13 | app.use(bodyParser.json()); | 16 | app.use(bodyParser.json()); |
... | @@ -23,6 +26,48 @@ app.post('/hook', function (req, res) { | ... | @@ -23,6 +26,48 @@ app.post('/hook', function (req, res) { |
23 | console.log('[request source] ', eventObj.source); | 26 | console.log('[request source] ', eventObj.source); |
24 | console.log('[request message]', eventObj.message); | 27 | console.log('[request message]', eventObj.message); |
25 | 28 | ||
29 | + if (true) { | ||
30 | + var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI(message.text); // json 결과 | ||
31 | + var options = { | ||
32 | + url: api_url, | ||
33 | + headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret} | ||
34 | + }; | ||
35 | + request.get(options, function (error, response, body) { | ||
36 | + const obj = JSON.parse(body); | ||
37 | + const str = JSON.stringify(obj.items[0]); | ||
38 | + const obj2 = JSON.parse(str); | ||
39 | + if (!error && response.statusCode == 200) { | ||
40 | + request.post( | ||
41 | + { | ||
42 | + url: TARGET_URL, | ||
43 | + headers: { | ||
44 | + 'Authorization': `Bearer ${TOKEN}` | ||
45 | + }, | ||
46 | + json: { | ||
47 | + "replyToken":eventObj.replyToken, | ||
48 | + "messages": [ | ||
49 | + { | ||
50 | + "type":"text", | ||
51 | + "text": JSON.stringify(obj2.link) | ||
52 | + }, | ||
53 | + { | ||
54 | + "type":"text", | ||
55 | + "text": JSON.stringify(obj2.description).replace(/<[^>]*>?/g, '') | ||
56 | + } | ||
57 | + ] | ||
58 | + } | ||
59 | + },(error, response, body) => { | ||
60 | + console.log(body) | ||
61 | + } | ||
62 | + ) | ||
63 | + } else { | ||
64 | + res.status(response.statusCode).end(); | ||
65 | + console.log('error = ' + response.statusCode); | ||
66 | + } | ||
67 | + }); | ||
68 | + | ||
69 | + } | ||
70 | + | ||
26 | if (message.text == 'help') { | 71 | if (message.text == 'help') { |
27 | request.post( | 72 | request.post( |
28 | { | 73 | { |
... | @@ -39,7 +84,7 @@ app.post('/hook', function (req, res) { | ... | @@ -39,7 +84,7 @@ app.post('/hook', function (req, res) { |
39 | }, | 84 | }, |
40 | { | 85 | { |
41 | "type":"text", | 86 | "type":"text", |
42 | - "text":"May I help you?" | 87 | + "text":"주식 관련 뉴스를 원하시면 \'뉴스\' 입력 후 원하는 종목을 검색하세요." |
43 | } | 88 | } |
44 | ] | 89 | ] |
45 | } | 90 | } | ... | ... |
-
Please register or login to post a comment