장수창

added news reply

...@@ -44,7 +44,11 @@ app.post('/hook', function (req, res) { ...@@ -44,7 +44,11 @@ app.post('/hook', function (req, res) {
44 44
45 var sub_hello = "어떻게" 45 var sub_hello = "어떻게"
46 if(message.text == "야" || message.text == "도움말" || message.text.indexOf(sub_hello) !== -1){ 46 if(message.text == "야" || message.text == "도움말" || message.text.indexOf(sub_hello) !== -1){
47 - hello(eventObj) 47 + hello(eventObj);
48 + }
49 +
50 + if(message.text.indexOf("뉴스") !== -1){
51 + replyNews(eventObj);
48 } 52 }
49 53
50 res.sendStatus(200); 54 res.sendStatus(200);
...@@ -117,6 +121,10 @@ function hello(eventObj) { ...@@ -117,6 +121,10 @@ function hello(eventObj) {
117 "text":"국내 현황은 '국내'를 타이핑 해주세요." 121 "text":"국내 현황은 '국내'를 타이핑 해주세요."
118 }, 122 },
119 { 123 {
124 + "type":"text",
125 + "text":"코로나 19 관련 뉴스는 '뉴스'를 타이핑 해주세요."
126 + },
127 + {
120 "type": "sticker", 128 "type": "sticker",
121 "packageId": "11539", 129 "packageId": "11539",
122 "stickerId": "52114110" 130 "stickerId": "52114110"
...@@ -167,11 +175,11 @@ function broadcast(){ ...@@ -167,11 +175,11 @@ function broadcast(){
167 // "messages":[ 175 // "messages":[
168 // { 176 // {
169 // "type":"text", 177 // "type":"text",
170 -// "text":"Hello, user" 178 +// "text":"용인시"
171 // }, 179 // },
172 // { 180 // {
173 // "type":"text", 181 // "type":"text",
174 -// "text":"May I help you?" 182 +// "text":"용인시"
175 // } 183 // }
176 // ] 184 // ]
177 // } 185 // }
...@@ -179,10 +187,11 @@ function broadcast(){ ...@@ -179,10 +187,11 @@ function broadcast(){
179 // console.log(body) 187 // console.log(body)
180 // }); 188 // });
181 189
182 -function news_Crawling() { 190 +//reply news
191 +function replyNews(eventObj) {
183 192
184 - var news_Title = ['title1', 'title2', 'title3', 'title4', 'title5'] 193 + var news_Title = ['title1', 'title2', 'title3', 'title4', 'title5'];
185 - var news_Link = ['link1', 'link2', 'link3', 'link4', 'link5'] 194 + var news_Link = ['link1', 'link2', 'link3', 'link4', 'link5'];
186 request.get({ 195 request.get({
187 url: 'https://openapi.naver.com/v1/search/news', 196 url: 'https://openapi.naver.com/v1/search/news',
188 qs: { 197 qs: {
...@@ -202,6 +211,42 @@ function news_Crawling() { ...@@ -202,6 +211,42 @@ function news_Crawling() {
202 news_Title[i] = json.items[i].title.replace('<b>', '').replace('</b>', '').replace('&quot;', '').replace('&quot;', ''); 211 news_Title[i] = json.items[i].title.replace('<b>', '').replace('</b>', '').replace('&quot;', '').replace('&quot;', '');
203 news_Link[i] = json.items[i].link; 212 news_Link[i] = json.items[i].link;
204 } 213 }
214 +
215 + request.post(
216 + {
217 + url: TARGET_URL,
218 + headers: {
219 + 'Authorization': `Bearer ${TOKEN}`
220 + },
221 + json: {
222 + "replyToken": eventObj.replyToken,
223 + "messages": [
224 + {
225 + "type": "text",
226 + "text": news_Title[0] + '\n' + news_Link[0]
227 + },
228 + {
229 + "type": "text",
230 + "text": news_Title[1] + '\n' + news_Link[1]
231 + },
232 + {
233 + "type":"text",
234 + "text":news_Title[2] + '\n' + news_Link[2]
235 + },
236 + {
237 + "type":"text",
238 + "text":news_Title[3] + '\n' + news_Link[3]
239 + },
240 + {
241 + "type":"text",
242 + "text":news_Title[4] + '\n' + news_Link[4]
243 + }
244 +
245 + ]
246 + }
247 + }, (error, response, body) => {
248 + console.log(body)
249 + });
205 }) 250 })
206 } 251 }
207 252
......