Showing
1 changed file
with
34 additions
and
35 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,14 +13,40 @@ const bodyParser = require('body-parser'); | ... | @@ -14,14 +13,40 @@ 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 = [ |
17 | + {index : 1, kr_name: "한식", en_name: 'korean food'}, | ||
18 | + {index : 2, kr_name: "중식", en_name: 'chinese food'}, | ||
19 | + {index : 3, kr_name: "양식", en_name: 'western food'}, | ||
20 | + {index : 4, kr_name: "일식", en_name: 'japanese food'}, | ||
21 | + {index : 5, kr_name: "분식", en_name: 'snack food'}, | ||
22 | + {index : 6, kr_name: "아시안", en_name: 'asian food'}, | ||
23 | + {index: 7, kr_name: "패스트푸드", en_name: 'fast food'}, | ||
24 | + {index: 8, kr_name: "학식", en_name: 'school food'} | ||
25 | +]; | ||
26 | + | ||
27 | +app.post('/hook', function (req, res) { | ||
28 | + | ||
29 | + var eventObj = req.body.events[0]; | ||
30 | + var source = eventObj.source; | ||
31 | + var message = eventObj.message; | ||
32 | + | ||
33 | + // request log | ||
34 | + console.log('======================', new Date() ,'======================'); | ||
35 | + console.log('[request]', req.body); | ||
36 | + console.log('[request source] ', eventObj.source); | ||
37 | + console.log('[request message]', eventObj.message); | ||
38 | + | ||
39 | + var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text.toLowerCase()); | ||
40 | + | ||
41 | + if (message.text == "안내" || message.text.toLowerCase() == "guide"){ | ||
42 | + request.post( | ||
18 | { | 43 | { |
19 | - url: PUSH_TARGET_URL, | 44 | + url: REPLY_TARGET_URL, |
20 | headers: { | 45 | headers: { |
21 | 'Authorization': `Bearer ${TOKEN}` | 46 | 'Authorization': `Bearer ${TOKEN}` |
22 | }, | 47 | }, |
23 | json: { | 48 | json: { |
24 | - "to": `${USER_ID}`, | 49 | + "replyToken":eventObj.replyToken, |
25 | "messages":[ | 50 | "messages":[ |
26 | { | 51 | { |
27 | "type":"sticker", | 52 | "type":"sticker", |
... | @@ -51,39 +76,13 @@ request.post( | ... | @@ -51,39 +76,13 @@ request.post( |
51 | },(error, response, body) => { | 76 | },(error, response, body) => { |
52 | console.log(body) | 77 | console.log(body) |
53 | }); | 78 | }); |
54 | - | 79 | + } |
55 | -app.post('/hook', function (req, res) { | 80 | + else if (food != undefined){ |
56 | - | ||
57 | - var eventObj = req.body.events[0]; | ||
58 | - var source = eventObj.source; | ||
59 | - var message = eventObj.message; | ||
60 | - | ||
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 | ||
73 | - console.log('======================', new Date() ,'======================'); | ||
74 | - console.log('[request]', req.body); | ||
75 | - console.log('[request source] ', eventObj.source); | ||
76 | - console.log('[request message]', eventObj.message); | ||
77 | - | ||
78 | - var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text); | ||
79 | - | ||
80 | - console.log(food); | ||
81 | - if (food != undefined){ | ||
82 | request.post( | 81 | request.post( |
83 | { | 82 | { |
84 | url: REPLY_TARGET_URL, | 83 | url: REPLY_TARGET_URL, |
85 | headers: { | 84 | headers: { |
86 | - 'Authorization': `Bearer ${TOKEN}` | 85 | + Authorization: `Bearer ${TOKEN}` |
87 | }, | 86 | }, |
88 | json: { | 87 | json: { |
89 | "replyToken":eventObj.replyToken, | 88 | "replyToken":eventObj.replyToken, |
... | @@ -92,8 +91,8 @@ app.post('/hook', function (req, res) { | ... | @@ -92,8 +91,8 @@ app.post('/hook', function (req, res) { |
92 | "type": "location", | 91 | "type": "location", |
93 | "title": "my location", | 92 | "title": "my location", |
94 | "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan", | 93 | "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan", |
95 | - "latitude": 35.687574, | 94 | + "latitude": 37.5666805, |
96 | - "longitude": 139.72922 | 95 | + "longitude": 126.9784147 |
97 | } | 96 | } |
98 | ] | 97 | ] |
99 | } | 98 | } | ... | ... |
-
Please register or login to post a comment