root

update app.js

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