Showing
1 changed file
with
15 additions
and
4 deletions
... | @@ -70,14 +70,25 @@ function handleEvent(event) { | ... | @@ -70,14 +70,25 @@ function handleEvent(event) { |
70 | // 검색 기능 | 70 | // 검색 기능 |
71 | else if(event.message.text.substr(0,4) == "!검색 "){ | 71 | else if(event.message.text.substr(0,4) == "!검색 "){ |
72 | return new Promise(function(resolve, reject) { | 72 | return new Promise(function(resolve, reject) { |
73 | - var text_len = event.message.text; | 73 | + var text_len = event.message.text.length; |
74 | - search_api_url += '?query=' + String(event.message.text.substr(4, text_len - 4)) + '&display=1'; | ||
75 | var search_options = { | 74 | var search_options = { |
76 | - url : search_api_url, | 75 | + uri : search_api_url, |
76 | + qs : {query : event.message.text.substr(4, text_len - 4), display : 1}, | ||
77 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | 77 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
78 | }; | 78 | }; |
79 | request.get(search_options, function(error, response, body){ | 79 | request.get(search_options, function(error, response, body){ |
80 | - console.log(response); | 80 | + if (!error && response.statusCode == 200){ |
81 | + var title = JSON.parse(body).items[0].title; | ||
82 | + var link = JSON.parse(body).items[0].link; | ||
83 | + var description = JSON.parse(body).items[0].description; | ||
84 | + | ||
85 | + var result = { type: 'text', text: | ||
86 | + title + " : " + description + | ||
87 | + "/nlink : " + link | ||
88 | + }; | ||
89 | + client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | ||
90 | + } | ||
91 | + | ||
81 | }) | 92 | }) |
82 | }) | 93 | }) |
83 | } | 94 | } | ... | ... |
-
Please register or login to post a comment