Showing
1 changed file
with
170 additions
and
21 deletions
... | @@ -3,12 +3,12 @@ var client_id = 'v3M4wjolGLkrvNA3GUIW'; | ... | @@ -3,12 +3,12 @@ var client_id = 'v3M4wjolGLkrvNA3GUIW'; |
3 | var client_secret = 'fKF6vjkWhE'; | 3 | var client_secret = 'fKF6vjkWhE'; |
4 | const request = require('request'); | 4 | const request = require('request'); |
5 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 5 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
6 | -const TOKEN = 'w5i8sURqF5bof6DWeB87n+oCeWrYaFf7a5YZzfzN1jeITIlZ3PcOmZRcdGCo/djTuHhNxybfJ69y7Jex+7tipBNRynngfyWX9CK1L3EupuhnX8rubeCmJda7HvsQWXVo8ZDcwl2aLwXsE3kiYF2qEwdB04t89/1O/w1cDnyilFU=' | 6 | +const TOKEN = 'hMnfhBQc8nadyn5Ow6aejAVDUoUEp9N8YxOFxfOB2V83TOf0vjquT4cC8ll4Ccq4hkWJ8xHij53FzjMteqLLuUL6bZs+ZONI+f5aawIulRg4Y4FFBGp1O03awvgxGn503iyI7+5iQCEi80Kus6cRZQdB04t89/1O/w1cDnyilFU=' //수정해주세용 |
7 | -const SECRET = 'b0b4501ebc2813a2b0e586293a35b466' | 7 | +const SECRET = '270103fd4cbd81695ceb6d0ed7f85f4b' //수정해주세용 |
8 | const fs = require('fs'); | 8 | const fs = require('fs'); |
9 | const path = require('path'); | 9 | const path = require('path'); |
10 | const HTTPS = require('https'); | 10 | const HTTPS = require('https'); |
11 | -const domain = "www.osstest237.ml" | 11 | +const domain = "www.osschatbot.tk" //수정해주세용 |
12 | const sslport = 23023; | 12 | const sslport = 23023; |
13 | const line = require('@line/bot-sdk'); | 13 | const line = require('@line/bot-sdk'); |
14 | 14 | ||
... | @@ -22,6 +22,19 @@ var content_id = '' | ... | @@ -22,6 +22,19 @@ var content_id = '' |
22 | var imgDownloaded = false; | 22 | var imgDownloaded = false; |
23 | var downloadedImg = '' | 23 | var downloadedImg = '' |
24 | 24 | ||
25 | +//search | ||
26 | +var search_client_id = 'cnS9zzj0OZ3xPgHqtaLJ'; | ||
27 | +var search_client_secret = 'oQGaxdr7aq'; | ||
28 | + | ||
29 | +//data parsing | ||
30 | +var data=''; | ||
31 | +var title=''; | ||
32 | +var link=''; | ||
33 | +var category=''; | ||
34 | +var address=''; | ||
35 | +var roadAddress=''; | ||
36 | + | ||
37 | + | ||
25 | app.post('/hook', function (req, res) { | 38 | app.post('/hook', function (req, res) { |
26 | 39 | ||
27 | var eventObj = req.body.events[0]; | 40 | var eventObj = req.body.events[0]; |
... | @@ -38,8 +51,16 @@ app.post('/hook', function (req, res) { | ... | @@ -38,8 +51,16 @@ app.post('/hook', function (req, res) { |
38 | if (eventObj.message.type == 'location') { | 51 | if (eventObj.message.type == 'location') { |
39 | 52 | ||
40 | //위치 받아서 맛집 추천해주는 함수 | 53 | //위치 받아서 맛집 추천해주는 함수 |
54 | + var chatbotaddress=eventObj.message; | ||
55 | + var chatbotdata1=chatbotaddress.address; | ||
56 | + var chatbotdata2=chatbotdata1.split(' '); | ||
57 | + var place=chatbotdata2[0]; | ||
58 | + | ||
59 | + console.log(place); | ||
60 | + var menu=''; | ||
61 | + var query= place + ' ' + menu + ' 맛집'; //검색 원하는 문자열 | ||
62 | + RecommendationResult(eventObj.replyToken, query); | ||
41 | 63 | ||
42 | - RecommendationResult(eventObj.replyToken); | ||
43 | res.sendStatus(200); | 64 | res.sendStatus(200); |
44 | } else if (text == 'Cfr:Yes') { | 65 | } else if (text == 'Cfr:Yes') { |
45 | QuickReplyCfrYes(eventObj.replyToken); | 66 | QuickReplyCfrYes(eventObj.replyToken); |
... | @@ -51,8 +72,9 @@ app.post('/hook', function (req, res) { | ... | @@ -51,8 +72,9 @@ app.post('/hook', function (req, res) { |
51 | if (text == '랜덤 추천') { | 72 | if (text == '랜덤 추천') { |
52 | 73 | ||
53 | //랜덤으로 맛집 추천해주는 함수 | 74 | //랜덤으로 맛집 추천해주는 함수 |
75 | + var query = '맛집'; | ||
76 | + RecommendationResult(eventObj.replyToken, query); | ||
54 | 77 | ||
55 | - RecommendationResult(eventObj.replyToken); | ||
56 | res.sendStatus(200); | 78 | res.sendStatus(200); |
57 | } | 79 | } |
58 | else { | 80 | else { |
... | @@ -169,7 +191,7 @@ function initReply (replyToken) { | ... | @@ -169,7 +191,7 @@ function initReply (replyToken) { |
169 | }, | 191 | }, |
170 | { | 192 | { |
171 | "type": "text", | 193 | "type": "text", |
172 | - "text": "안녕하세요.\nCFR을 이용한 경기도 맛집 추천봇입니다." | 194 | + "text": "안녕하세요.\nCFR을 이용한 얼굴인식 맛집 추천봇입니다." |
173 | }, | 195 | }, |
174 | { | 196 | { |
175 | "type": "template", | 197 | "type": "template", |
... | @@ -215,7 +237,8 @@ function SendingLocation(replyToken) { | ... | @@ -215,7 +237,8 @@ function SendingLocation(replyToken) { |
215 | "quickReply": quickReplyLocation | 237 | "quickReply": quickReplyLocation |
216 | } | 238 | } |
217 | ] | 239 | ] |
218 | - } | 240 | + }, |
241 | + body: request | ||
219 | },(error, response, body) => { | 242 | },(error, response, body) => { |
220 | console.log(body) | 243 | console.log(body) |
221 | }); | 244 | }); |
... | @@ -289,8 +312,42 @@ function Checking (replyToken) { | ... | @@ -289,8 +312,42 @@ function Checking (replyToken) { |
289 | }); | 312 | }); |
290 | } | 313 | } |
291 | 314 | ||
292 | -//추천 결과 | 315 | + |
293 | -function RecommendationResult(replyToken) { | 316 | +//추천 결과 + Search |
317 | +function RecommendationResult(replyToken, query) { | ||
318 | + | ||
319 | + console.log(query); | ||
320 | + var display = '1'; //검색 결과 출력 건수. 최대 5개 | ||
321 | + var start = '1'; //검색 시작 위치. 1만 가능 | ||
322 | + var sort = 'comment'; //정렬 옵션 (random : 유사도순, comment : 카페/블로그 리뷰 개수 순) | ||
323 | + | ||
324 | + var api_url = 'https://openapi.naver.com/v1/search/local?query=' + encodeURI(query) + '&display=' + encodeURI(display) + '&start=' + encodeURI(start) + '&sort=' + encodeURI(sort); | ||
325 | + var options = { | ||
326 | + url: api_url, | ||
327 | + headers: { 'X-Naver-Client-Id': search_client_id, 'X-Naver-Client-Secret': search_client_secret } | ||
328 | + }; | ||
329 | + request.get(options, function (error, response, body) { | ||
330 | + if (!error && response.statusCode == 200) { | ||
331 | + //response.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); | ||
332 | + console.log(body); | ||
333 | + | ||
334 | + //데이터 parsing | ||
335 | + data = JSON.parse(body); | ||
336 | + title = data.items[0].title; | ||
337 | + console.log(title); | ||
338 | + | ||
339 | + link = data.items[0].link; | ||
340 | + console.log(link); | ||
341 | + | ||
342 | + category = data.items[0].category; | ||
343 | + console.log(category); | ||
344 | + | ||
345 | + address = data.items[0].address; | ||
346 | + console.log(address); | ||
347 | + | ||
348 | + roadAddress = data.items[0].roadAddress; | ||
349 | + console.log(roadAddress); | ||
350 | + | ||
294 | request.post( | 351 | request.post( |
295 | { | 352 | { |
296 | url: TARGET_URL, | 353 | url: TARGET_URL, |
... | @@ -300,7 +357,7 @@ function RecommendationResult(replyToken) { | ... | @@ -300,7 +357,7 @@ function RecommendationResult(replyToken) { |
300 | json: { | 357 | json: { |
301 | "replyToken": replyToken, | 358 | "replyToken": replyToken, |
302 | "messages": [ | 359 | "messages": [ |
303 | - { | 360 | + /*{ |
304 | "type": "imagemap", | 361 | "type": "imagemap", |
305 | // 이미지 불러올 수 없습니다 뜸 | 362 | // 이미지 불러올 수 없습니다 뜸 |
306 | "baseUrl": "https://www.flaticon.com/free-icon/food-store_2934069?term=restaurant&page=1&position=7&related_item_id=2934069", | 363 | "baseUrl": "https://www.flaticon.com/free-icon/food-store_2934069?term=restaurant&page=1&position=7&related_item_id=2934069", |
... | @@ -312,25 +369,41 @@ function RecommendationResult(replyToken) { | ... | @@ -312,25 +369,41 @@ function RecommendationResult(replyToken) { |
312 | "actions": [ | 369 | "actions": [ |
313 | { | 370 | { |
314 | "type": "uri", | 371 | "type": "uri", |
315 | - "linkUri": `${link}`, // 가게 링크 | 372 | + "linkUri": link, // 가게 링크 |
316 | "area": { | 373 | "area": { |
317 | - "x":0, | 374 | + "x": 0, |
318 | - "y":0, | 375 | + "y": 0, |
319 | - "width":1040, | 376 | + "width": 1040, |
320 | - "height":1040 | 377 | + "height": 1040 |
321 | } | 378 | } |
322 | } | 379 | } |
323 | ] | 380 | ] |
324 | - }, | 381 | + },*/ |
325 | { | 382 | { |
326 | "type": "text", | 383 | "type": "text", |
327 | - "text": "기타 결과 출력" // 정보 수정 | 384 | + "text": "맛집 이름: " + title |
385 | + }, | ||
386 | + { | ||
387 | + "type":"text", | ||
388 | + "text": "맛집 주소: " + address | ||
328 | } | 389 | } |
390 | + /*{ | ||
391 | + "type":"location", | ||
392 | + "title":"맛집 주소", | ||
393 | + "address":address | ||
394 | + }*/ | ||
329 | ] | 395 | ] |
330 | } | 396 | } |
331 | - },(error, response, body) => { | 397 | + }, (error, response, body) => { |
332 | console.log(body) | 398 | console.log(body) |
333 | }); | 399 | }); |
400 | + | ||
401 | + } else { | ||
402 | + res.status(response.statusCode).end(); | ||
403 | + console.log('error = ' + response.statusCode); | ||
404 | + } | ||
405 | + }) | ||
406 | + | ||
334 | } | 407 | } |
335 | 408 | ||
336 | imgtodata = function(dir){ | 409 | imgtodata = function(dir){ |
... | @@ -349,14 +422,90 @@ imgtodata = function(dir){ | ... | @@ -349,14 +422,90 @@ imgtodata = function(dir){ |
349 | }, (err,response,body) =>{ | 422 | }, (err,response,body) =>{ |
350 | console.log(response.statusCode); // 200 | 423 | console.log(response.statusCode); // 200 |
351 | //console.log(response.headers['content-type']) | 424 | //console.log(response.headers['content-type']) |
425 | + console.log(body); | ||
426 | + var cfrdata=JSON.parse(body); | ||
427 | + | ||
428 | + var cfrgender=cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json) | ||
429 | + var cfremotion=cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json) | ||
430 | + | ||
431 | + var gender = cfrgender; //사용자 성별 | ||
432 | + var emotion = cfremotion; //사용자 감정 | ||
352 | 433 | ||
353 | - data=JSON.parse(body); | ||
354 | - gender=data.faces[0].gender.value; | ||
355 | - emotion=data.faces[0].emotion.value | ||
356 | 434 | ||
357 | console.log(gender); | 435 | console.log(gender); |
358 | console.log(emotion); | 436 | console.log(emotion); |
359 | 437 | ||
438 | + if(gender=='male'){ | ||
439 | + if(emotion=='angry'){ | ||
440 | + menu='술'; | ||
441 | + } | ||
442 | + else if(emotion=='disgust'){ | ||
443 | + menu='야식'; | ||
444 | + } | ||
445 | + else if(emotion=='fear'){ | ||
446 | + menu='한식'; | ||
447 | + } | ||
448 | + else if(emotion=='laugh'){ | ||
449 | + menu='치킨'; | ||
450 | + } | ||
451 | + else if(emotion=='neutral'){ | ||
452 | + menu='양식'; | ||
453 | + } | ||
454 | + else if(emotion=='sad'){ | ||
455 | + menu='중식'; | ||
456 | + } | ||
457 | + else if(emotion=='surprise'){ | ||
458 | + menu='일식'; | ||
459 | + } | ||
460 | + else if(emotion=='smile'){ | ||
461 | + menu='고기'; | ||
462 | + } | ||
463 | + else if(emotion=='talking'){ | ||
464 | + menu='술'; | ||
465 | + } | ||
466 | + else{ | ||
467 | + menu=''; | ||
468 | + } | ||
469 | + } | ||
470 | + else if(gender=='female'){ | ||
471 | + if(emotion=='angry'){ | ||
472 | + menu='고기'; | ||
473 | + } | ||
474 | + else if(emotion=='disgust'){ | ||
475 | + menu='디저트'; | ||
476 | + } | ||
477 | + else if(emotion=='fear'){ | ||
478 | + menu='한식'; | ||
479 | + } | ||
480 | + else if(emotion=='laugh'){ | ||
481 | + menu='일식'; | ||
482 | + } | ||
483 | + else if(emotion=='neutral'){ | ||
484 | + menu='중식'; | ||
485 | + } | ||
486 | + else if(emotion=='sad'){ | ||
487 | + menu='야식'; | ||
488 | + } | ||
489 | + else if(emotion=='surprise'){ | ||
490 | + menu='중식'; | ||
491 | + } | ||
492 | + else if(emotion=='smile'){ | ||
493 | + menu='치킨'; | ||
494 | + } | ||
495 | + else if(emotion=='talking'){ | ||
496 | + menu='카페'; | ||
497 | + } | ||
498 | + else{ | ||
499 | + menu=''; | ||
500 | + } | ||
501 | + } | ||
502 | + else{ | ||
503 | + menu=''; | ||
504 | + } | ||
505 | + | ||
506 | + console.log(menu); | ||
507 | + | ||
508 | + | ||
360 | //return {gender:gender,emotion:emotion}; | 509 | //return {gender:gender,emotion:emotion}; |
361 | }); | 510 | }); |
362 | } | 511 | } | ... | ... |
-
Please register or login to post a comment