Showing
1 changed file
with
57 additions
and
58 deletions
| ... | @@ -3,7 +3,6 @@ const request = require('request'); | ... | @@ -3,7 +3,6 @@ const request = require('request'); |
| 3 | const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push' | 3 | const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push' |
| 4 | const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 4 | const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
| 5 | const TOKEN = 'Zd+BLpi6wLHMngB3EK74S1W7ApnAXuYZ86xGIi60JKrSW0xI0JyXlCzpunYxk9fxtOkH4y2/CNrb6K7WYldpXBwUkCKNIyEQ04AUpQKQ1EzS6C3qm6y5sBm0zs/Gmzn6n1v1jLfmSpxyLir7VqHk5wdB04t89/1O/w1cDnyilFU=' | 5 | const TOKEN = 'Zd+BLpi6wLHMngB3EK74S1W7ApnAXuYZ86xGIi60JKrSW0xI0JyXlCzpunYxk9fxtOkH4y2/CNrb6K7WYldpXBwUkCKNIyEQ04AUpQKQ1EzS6C3qm6y5sBm0zs/Gmzn6n1v1jLfmSpxyLir7VqHk5wdB04t89/1O/w1cDnyilFU=' |
| 6 | -const USER_ID = 'Uaa6ee8ae309532533aead588d062180d' | ||
| 7 | const fs = require('fs'); | 6 | const fs = require('fs'); |
| 8 | const path = require('path'); | 7 | const path = require('path'); |
| 9 | const HTTPS = require('https'); | 8 | const HTTPS = require('https'); |
| ... | @@ -14,43 +13,16 @@ const bodyParser = require('body-parser'); | ... | @@ -14,43 +13,16 @@ const bodyParser = require('body-parser'); |
| 14 | var app = express(); | 13 | var app = express(); |
| 15 | app.use(bodyParser.json()); | 14 | app.use(bodyParser.json()); |
| 16 | 15 | ||
| 17 | -request.post( | 16 | +const foodArr = [ |
| 18 | - { | 17 | + {index : 1, kr_name: "한식", en_name: 'korean food'}, |
| 19 | - url: PUSH_TARGET_URL, | 18 | + {index : 2, kr_name: "중식", en_name: 'chinese food'}, |
| 20 | - headers: { | 19 | + {index : 3, kr_name: "양식", en_name: 'western food'}, |
| 21 | - 'Authorization': `Bearer ${TOKEN}` | 20 | + {index : 4, kr_name: "일식", en_name: 'japanese food'}, |
| 22 | - }, | 21 | + {index : 5, kr_name: "분식", en_name: 'snack food'}, |
| 23 | - json: { | 22 | + {index : 6, kr_name: "아시안", en_name: 'asian food'}, |
| 24 | - "to": `${USER_ID}`, | 23 | + {index: 7, kr_name: "패스트푸드", en_name: 'fast food'}, |
| 25 | - "messages":[ | 24 | + {index: 8, kr_name: "학식", en_name: 'school food'} |
| 26 | - { | 25 | +]; |
| 27 | - "type":"sticker", | ||
| 28 | - "packageId":"11538", | ||
| 29 | - "stickerId":"51626517" | ||
| 30 | - }, | ||
| 31 | - { | ||
| 32 | - "type":"text", | ||
| 33 | - "text":"안녕하세요\n"+ | ||
| 34 | - "음식추천 챗봇 쿠밥봇입니다\n\n"+ | ||
| 35 | - "원하시는 메뉴를 골라주세요\n\n"+ | ||
| 36 | - "1.한식2.중식3.양식\n"+ | ||
| 37 | - "4.일식.5.분식6.아시안\n"+ | ||
| 38 | - "7.패스트푸드8.학식" | ||
| 39 | - }, | ||
| 40 | - { | ||
| 41 | - "type":"text", | ||
| 42 | - "text":"Welcome!!!\n" + | ||
| 43 | - "I'm a food recommendation chatbot, KHUBABBOT\n"+ | ||
| 44 | - "Please choose the menu you want\n"+ | ||
| 45 | - "1. Korean food 2. Chinese food 3. Western food\n"+ | ||
| 46 | - "4. Japanese food 5. Snack food 6. Asian food\n"+ | ||
| 47 | - "7. Fast food 8. School food\n" | ||
| 48 | - } | ||
| 49 | - ] | ||
| 50 | - } | ||
| 51 | - },(error, response, body) => { | ||
| 52 | - console.log(body) | ||
| 53 | - }); | ||
| 54 | 26 | ||
| 55 | app.post('/hook', function (req, res) { | 27 | app.post('/hook', function (req, res) { |
| 56 | 28 | ||
| ... | @@ -58,27 +30,15 @@ app.post('/hook', function (req, res) { | ... | @@ -58,27 +30,15 @@ app.post('/hook', function (req, res) { |
| 58 | var source = eventObj.source; | 30 | var source = eventObj.source; |
| 59 | var message = eventObj.message; | 31 | var message = eventObj.message; |
| 60 | 32 | ||
| 61 | - const foodArr = [ | ||
| 62 | - {index : 1, kr_name: "한식", en_name: 'Korean food'}, | ||
| 63 | - {index : 2, kr_name: "중식", en_name: 'Chinese food'}, | ||
| 64 | - {index : 3, kr_name: "양식", en_name: 'Western food'}, | ||
| 65 | - {index : 4, kr_name: "일식", en_name: 'Japanese food'}, | ||
| 66 | - {index : 5, kr_name: "분식", en_name: 'Snack food'}, | ||
| 67 | - {index : 6, kr_name: "아시안", en_name: 'Asian food'}, | ||
| 68 | - {index: 7, kr_name: "패스트푸드", en_name: 'Fast food'}, | ||
| 69 | - {index: 8, kr_name: "학식", en_name: 'School food'} | ||
| 70 | - ]; | ||
| 71 | - | ||
| 72 | // request log | 33 | // request log |
| 73 | console.log('======================', new Date() ,'======================'); | 34 | console.log('======================', new Date() ,'======================'); |
| 74 | console.log('[request]', req.body); | 35 | console.log('[request]', req.body); |
| 75 | console.log('[request source] ', eventObj.source); | 36 | console.log('[request source] ', eventObj.source); |
| 76 | console.log('[request message]', eventObj.message); | 37 | console.log('[request message]', eventObj.message); |
| 77 | 38 | ||
| 78 | - var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text); | 39 | + var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text.toLowerCase()); |
| 79 | - | 40 | + |
| 80 | - console.log(food); | 41 | + if (message.text == "안내" || message.text.toLowerCase() == "guide"){ |
| 81 | - if (food != undefined){ | ||
| 82 | request.post( | 42 | request.post( |
| 83 | { | 43 | { |
| 84 | url: REPLY_TARGET_URL, | 44 | url: REPLY_TARGET_URL, |
| ... | @@ -89,11 +49,50 @@ app.post('/hook', function (req, res) { | ... | @@ -89,11 +49,50 @@ app.post('/hook', function (req, res) { |
| 89 | "replyToken":eventObj.replyToken, | 49 | "replyToken":eventObj.replyToken, |
| 90 | "messages":[ | 50 | "messages":[ |
| 91 | { | 51 | { |
| 92 | - "type": "location", | 52 | + "type":"sticker", |
| 93 | - "title": "my location", | 53 | + "packageId":"11538", |
| 94 | - "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan", | 54 | + "stickerId":"51626517" |
| 95 | - "latitude": 35.687574, | 55 | + }, |
| 96 | - "longitude": 139.72922 | 56 | + { |
| 57 | + "type":"text", | ||
| 58 | + "text":"안녕하세요\n"+ | ||
| 59 | + "음식추천 챗봇 쿠밥봇입니다\n\n"+ | ||
| 60 | + "원하시는 메뉴를 골라주세요\n\n"+ | ||
| 61 | + "1.한식2.중식3.양식\n"+ | ||
| 62 | + "4.일식.5.분식6.아시안\n"+ | ||
| 63 | + "7.패스트푸드8.학식" | ||
| 64 | + }, | ||
| 65 | + { | ||
| 66 | + "type":"text", | ||
| 67 | + "text":"Welcome!!!\n" + | ||
| 68 | + "I'm a food recommendation chatbot, KHUBABBOT\n"+ | ||
| 69 | + "Please choose the menu you want\n"+ | ||
| 70 | + "1. Korean food 2. Chinese food 3. Western food\n"+ | ||
| 71 | + "4. Japanese food 5. Snack food 6. Asian food\n"+ | ||
| 72 | + "7. Fast food 8. School food\n" | ||
| 73 | + } | ||
| 74 | + ] | ||
| 75 | + } | ||
| 76 | + },(error, response, body) => { | ||
| 77 | + console.log(body) | ||
| 78 | + }); | ||
| 79 | + } | ||
| 80 | + else if (food != undefined){ | ||
| 81 | + request.post( | ||
| 82 | + { | ||
| 83 | + url: REPLY_TARGET_URL, | ||
| 84 | + headers: { | ||
| 85 | + Authorization: `Bearer ${TOKEN}` | ||
| 86 | + }, | ||
| 87 | + json: { | ||
| 88 | + "replyToken":eventObj.replyToken, | ||
| 89 | + "messages":[ | ||
| 90 | + { | ||
| 91 | + "type": "location", | ||
| 92 | + "title": "my location", | ||
| 93 | + "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan", | ||
| 94 | + "latitude": 37.5666805, | ||
| 95 | + "longitude": 126.9784147 | ||
| 97 | } | 96 | } |
| 98 | ] | 97 | ] |
| 99 | } | 98 | } | ... | ... |
-
Please register or login to post a comment