Showing
1 changed file
with
61 additions
and
17 deletions
| ... | @@ -11,16 +11,7 @@ const sslport = 23023; | ... | @@ -11,16 +11,7 @@ const sslport = 23023; |
| 11 | const bodyParser = require('body-parser'); | 11 | const bodyParser = require('body-parser'); |
| 12 | const app = express(); | 12 | const app = express(); |
| 13 | 13 | ||
| 14 | - | 14 | +function main(eventObj,res){ |
| 15 | - | ||
| 16 | -app.use(bodyParser.json()); | ||
| 17 | -app.post('/hook', function (req, res) { | ||
| 18 | - var eventObj = req.body.events[0]; | ||
| 19 | - //var source = eventObj.source; | ||
| 20 | - //var message = eventObj.message; | ||
| 21 | - // request log | ||
| 22 | - console.log('======================', new Date() ,'======================'); | ||
| 23 | - console.log((Address.getAddress('석수동길')).road_address.address_name) | ||
| 24 | request.post( | 15 | request.post( |
| 25 | { | 16 | { |
| 26 | url: TARGET_URL, | 17 | url: TARGET_URL, |
| ... | @@ -31,21 +22,74 @@ app.post('/hook', function (req, res) { | ... | @@ -31,21 +22,74 @@ app.post('/hook', function (req, res) { |
| 31 | "replyToken":eventObj.replyToken, //eventObj.replyToken | 22 | "replyToken":eventObj.replyToken, //eventObj.replyToken |
| 32 | "messages":[ | 23 | "messages":[ |
| 33 | { | 24 | { |
| 34 | - "type":"text", | 25 | + "type": "text", // ① |
| 35 | - "text":address | 26 | + "text": "응급 상황인가요?", |
| 27 | + "quickReply": { // ② | ||
| 28 | + "items": [ | ||
| 29 | + { | ||
| 30 | + "type": "action", // ③ | ||
| 31 | + "action": { | ||
| 32 | + "type": "postback", | ||
| 33 | + "label": "네", | ||
| 34 | + "data": "action=two", | ||
| 35 | + "displayText": "네", | ||
| 36 | + "inputOption": "openKeyboard", | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + ] | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + ], | ||
| 43 | + } | ||
| 44 | + },(error, response, body) => { | ||
| 45 | + | ||
| 46 | + }); | ||
| 47 | + | ||
| 48 | +res.sendStatus(200); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +function find_current(eventObj,res){ //Two | ||
| 52 | + request.post( | ||
| 53 | + { | ||
| 54 | + url: TARGET_URL, | ||
| 55 | + headers: { | ||
| 56 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 36 | }, | 57 | }, |
| 58 | + json: { | ||
| 59 | + "replyToken":eventObj.replyToken, //eventObj.replyToken | ||
| 60 | + "messages":[ | ||
| 37 | { | 61 | { |
| 38 | - "type":"text", | 62 | + "type": "text", // ① |
| 39 | - "text":"맞나요?" | 63 | + "text": "응급 상황인가요?", |
| 64 | + "type": "text", // ① | ||
| 65 | + "text": "현재있는 위치의 주소나 보이는 곳을 입력하세요.", | ||
| 66 | + | ||
| 40 | } | 67 | } |
| 41 | ], | 68 | ], |
| 42 | - "status" : 1 | ||
| 43 | } | 69 | } |
| 44 | },(error, response, body) => { | 70 | },(error, response, body) => { |
| 45 | - console.log(body) | 71 | + |
| 46 | }); | 72 | }); |
| 47 | 73 | ||
| 48 | - res.sendStatus(200); | 74 | +res.sendStatus(200); |
| 75 | +} | ||
| 76 | + | ||
| 77 | + | ||
| 78 | +app.use(bodyParser.json()); | ||
| 79 | +app.post('/hook', function (req, res) { | ||
| 80 | + var eventObj = req.body.events[0]; | ||
| 81 | + console.log('======================', new Date() ,'======================'); | ||
| 82 | + console.log(eventObj) | ||
| 83 | + if(eventObj.postback){ | ||
| 84 | + | ||
| 85 | + find_current(eventObj,res) | ||
| 86 | + | ||
| 87 | + | ||
| 88 | + } | ||
| 89 | + else{ | ||
| 90 | + find_current(eventObj,res) | ||
| 91 | + } | ||
| 92 | + | ||
| 49 | }); | 93 | }); |
| 50 | 94 | ||
| 51 | 95 | ... | ... |
-
Please register or login to post a comment