Showing
1 changed file
with
52 additions
and
0 deletions
routes/line.js
0 → 100644
| 1 | +const bodyParser = require('body-parser'); | ||
| 2 | + | ||
| 3 | +app.use(bodyParser.json()); | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +app.post('/webhook', function (request, response) { | ||
| 8 | + | ||
| 9 | + var eventObj = request.body.events[0]; | ||
| 10 | + var source = eventObj.source; | ||
| 11 | + var message = eventObj.message; | ||
| 12 | + | ||
| 13 | + // request log | ||
| 14 | + console.log('======================', new Date() ,'======================'); | ||
| 15 | + console.log('[request]', request.body); | ||
| 16 | + console.log('[request source] ', eventObj.source); | ||
| 17 | + console.log('[request message]', eventObj.message); | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + if(message.type == "text"){ | ||
| 21 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, 'welcome sooinzzang.com'); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + /* | ||
| 26 | + | ||
| 27 | + if(message.type = "text" && message.text.indexOf("@momo") != -1){ | ||
| 28 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionBasic.getBasicExpress()); | ||
| 29 | + } | ||
| 30 | + else if(message.type = "text" && /^@.+/g.test(message.text)){ | ||
| 31 | + var cmd = message.text.split('@')[1]; | ||
| 32 | + console.log('[command]', cmd); | ||
| 33 | + | ||
| 34 | + if(typeof cmd !== "undefined" && cmd != ""){ | ||
| 35 | + if(cmd == "h" || cmd == "help"){ | ||
| 36 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionHelp.getHelpExpress()); | ||
| 37 | + } | ||
| 38 | + else if(/^r\[.+\]/g.test(cmd)){ | ||
| 39 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionEnjoy.getRandomExpress(cmd)); | ||
| 40 | + } | ||
| 41 | + else if(cmd == "food" || cmd == "밥집"){ | ||
| 42 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionEnjoy.getFoodExpress()); | ||
| 43 | + } | ||
| 44 | + else if(cmd == "contact" || cmd == "ct"){ | ||
| 45 | + reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionHelp.getContactExpress()); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + */ | ||
| 51 | + response.sendStatus(200); | ||
| 52 | +}); |
-
Please register or login to post a comment