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