Showing
1 changed file
with
61 additions
and
8 deletions
| ... | @@ -11,6 +11,9 @@ const sslport = 23023; | ... | @@ -11,6 +11,9 @@ const sslport = 23023; |
| 11 | var client_id = 'YOUR_CLIENT_ID'; | 11 | var client_id = 'YOUR_CLIENT_ID'; |
| 12 | var client_secret = 'YOUR_CLIENT_SECRET'; | 12 | var client_secret = 'YOUR_CLIENT_SECRET'; |
| 13 | 13 | ||
| 14 | +var newsOn = false; | ||
| 15 | +var newsOff = true; | ||
| 16 | + | ||
| 14 | const bodyParser = require('body-parser'); | 17 | const bodyParser = require('body-parser'); |
| 15 | var app = express(); | 18 | var app = express(); |
| 16 | app.use(bodyParser.json()); | 19 | app.use(bodyParser.json()); |
| ... | @@ -26,7 +29,51 @@ app.post('/hook', function (req, res) { | ... | @@ -26,7 +29,51 @@ app.post('/hook', function (req, res) { |
| 26 | console.log('[request source] ', eventObj.source); | 29 | console.log('[request source] ', eventObj.source); |
| 27 | console.log('[request message]', eventObj.message); | 30 | console.log('[request message]', eventObj.message); |
| 28 | 31 | ||
| 29 | - if (true) { | 32 | + if (message.text == 'news on') { |
| 33 | + newsOn = true; | ||
| 34 | + newsOff = false; | ||
| 35 | + request.post( | ||
| 36 | + { | ||
| 37 | + url: TARGET_URL, | ||
| 38 | + headers: { | ||
| 39 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 40 | + }, | ||
| 41 | + json: { | ||
| 42 | + "replyToken":eventObj.replyToken, | ||
| 43 | + "messages":[ | ||
| 44 | + { | ||
| 45 | + "type":"text", | ||
| 46 | + "text":"[news On] 키워드를 입력 하세요." | ||
| 47 | + } | ||
| 48 | + ] | ||
| 49 | + } | ||
| 50 | + },(error, response, body) => { | ||
| 51 | + console.log(body) | ||
| 52 | + }); | ||
| 53 | + } else if ( message.text == 'news off') { | ||
| 54 | + newsOn = false; | ||
| 55 | + newsOff = true; | ||
| 56 | + request.post( | ||
| 57 | + { | ||
| 58 | + url: TARGET_URL, | ||
| 59 | + headers: { | ||
| 60 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 61 | + }, | ||
| 62 | + json: { | ||
| 63 | + "replyToken":eventObj.replyToken, | ||
| 64 | + "messages":[ | ||
| 65 | + { | ||
| 66 | + "type":"text", | ||
| 67 | + "text":"[news Off] 뉴스를 종료합니다." | ||
| 68 | + } | ||
| 69 | + ] | ||
| 70 | + } | ||
| 71 | + },(error, response, body) => { | ||
| 72 | + console.log(body) | ||
| 73 | + }); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + if (newsOn & message.text != 'help' & message.text != 'news on') { | ||
| 30 | var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI(message.text); // json 결과 | 77 | var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI(message.text); // json 결과 |
| 31 | var options = { | 78 | var options = { |
| 32 | url: api_url, | 79 | url: api_url, |
| ... | @@ -48,11 +95,15 @@ app.post('/hook', function (req, res) { | ... | @@ -48,11 +95,15 @@ app.post('/hook', function (req, res) { |
| 48 | "messages": [ | 95 | "messages": [ |
| 49 | { | 96 | { |
| 50 | "type":"text", | 97 | "type":"text", |
| 51 | - "text": JSON.stringify(obj2.link) | 98 | + "text": "<<<헤드라인>>>\n" + JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '') |
| 99 | + }, | ||
| 100 | + { | ||
| 101 | + "type":"text", | ||
| 102 | + "text": "<<<주요문단>>>\n" + JSON.stringify(obj2.description).replace(/<[^>]*>?/g, '') | ||
| 52 | }, | 103 | }, |
| 53 | { | 104 | { |
| 54 | "type":"text", | 105 | "type":"text", |
| 55 | - "text": JSON.stringify(obj2.description).replace(/<[^>]*>?/g, '') | 106 | + "text": "뉴스 바로가기\n" + JSON.stringify(obj2.link) |
| 56 | } | 107 | } |
| 57 | ] | 108 | ] |
| 58 | } | 109 | } |
| ... | @@ -80,11 +131,13 @@ app.post('/hook', function (req, res) { | ... | @@ -80,11 +131,13 @@ app.post('/hook', function (req, res) { |
| 80 | "messages":[ | 131 | "messages":[ |
| 81 | { | 132 | { |
| 82 | "type":"text", | 133 | "type":"text", |
| 83 | - "text":"반갑습니다. 주식 알리미 입니다." | 134 | + "text":"*****************\ |
| 84 | - }, | 135 | + \n반갑습니다. 주식 news 알리미 입니다.\ |
| 85 | - { | 136 | + \n1. 뉴스 검색 기능 활성화\ |
| 86 | - "type":"text", | 137 | + \n\'news on\' 입력\ |
| 87 | - "text":"주식 관련 뉴스를 원하시면 \'뉴스\' 입력 후 원하는 종목을 검색하세요." | 138 | + \n2. 뉴스 검색 기능 비활성화\ |
| 139 | + \n\'news off\' 입력\ | ||
| 140 | + \n*****************" | ||
| 88 | } | 141 | } |
| 89 | ] | 142 | ] |
| 90 | } | 143 | } | ... | ... |
-
Please register or login to post a comment