최지민

search_option4

Showing 1 changed file with 15 additions and 4 deletions
......@@ -70,14 +70,25 @@ function handleEvent(event) {
// 검색 기능
else if(event.message.text.substr(0,4) == "!검색 "){
return new Promise(function(resolve, reject) {
var text_len = event.message.text;
search_api_url += '?query=' + String(event.message.text.substr(4, text_len - 4)) + '&display=1';
var text_len = event.message.text.length;
var search_options = {
url : search_api_url,
uri : search_api_url,
qs : {query : event.message.text.substr(4, text_len - 4), display : 1},
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
request.get(search_options, function(error, response, body){
console.log(response);
if (!error && response.statusCode == 200){
var title = JSON.parse(body).items[0].title;
var link = JSON.parse(body).items[0].link;
var description = JSON.parse(body).items[0].description;
var result = { type: 'text', text:
title + " : " + description +
"/nlink : " + link
};
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
})
})
}
......