Showing
1 changed file
with
95 additions
and
3 deletions
| ... | @@ -19,24 +19,116 @@ const sslport = 23023; | ... | @@ -19,24 +19,116 @@ const sslport = 23023; |
| 19 | const bodyParser = require('body-parser'); | 19 | const bodyParser = require('body-parser'); |
| 20 | var app = express(); | 20 | var app = express(); |
| 21 | app.use(bodyParser.json()); | 21 | app.use(bodyParser.json()); |
| 22 | + | ||
| 23 | + | ||
| 24 | +function first(text1){ | ||
| 25 | + if(text1 == '궁금해요') | ||
| 26 | + return true; | ||
| 27 | + else | ||
| 28 | + return false; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +function hello(text2){ | ||
| 32 | + request.post({ | ||
| 33 | + url: TARGET_URL, | ||
| 34 | + headers:{ | ||
| 35 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 36 | + }, | ||
| 37 | + json:{ | ||
| 38 | + "replyToken":eventObj,replyToken, | ||
| 39 | + "messages" :[ | ||
| 40 | + { | ||
| 41 | + "type":"text", | ||
| 42 | + "text": "안녕하세요, 식품 유해정보를 알려드립니다."; | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + "type":"text", | ||
| 46 | + "text": "무엇을 도와드릴까요?" | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + "type":"text", | ||
| 50 | + "text": "식품 유해정보가 궁금하시면 y를 입력해주세요" | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + ] | ||
| 54 | + } | ||
| 55 | + },(error,response,body)=>{ | ||
| 56 | + console.log(body) | ||
| 57 | + }); | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +function inputfood(eventObj){ | ||
| 61 | + request.post({ | ||
| 62 | + url: TARGET_URL, | ||
| 63 | + headers: { | ||
| 64 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 65 | + }, | ||
| 66 | + json:{ | ||
| 67 | + "replyToken" :eventObj.replyToken, | ||
| 68 | + "messages":[ | ||
| 69 | + { | ||
| 70 | + "type":"text", | ||
| 71 | + "text": "입력하신 상품은 " + eventObj.replyToken +"입니다." | ||
| 72 | + } | ||
| 73 | + ] | ||
| 74 | + } | ||
| 75 | + }, (error, response,body) =>{ | ||
| 76 | + console.log(body) | ||
| 77 | + | ||
| 78 | + }); | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +function findfood(foodtext){ | ||
| 82 | + //음식정보가 있으면 return true; | ||
| 83 | + //음식정보가 없으면 return false; | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +function printinformation(foodtext){ | ||
| 87 | + //유해정보 출력하기 | ||
| 88 | + | ||
| 89 | +} | ||
| 22 | app.post('/hook', function (req, res) { | 90 | app.post('/hook', function (req, res) { |
| 23 | 91 | ||
| 24 | var eventObj = req.body.events[0]; | 92 | var eventObj = req.body.events[0]; |
| 25 | var source = eventObj.source; | 93 | var source = eventObj.source; |
| 26 | var message = eventObj.message; | 94 | var message = eventObj.message; |
| 95 | + var text; | ||
| 96 | + var text1; | ||
| 97 | + var text2; | ||
| 27 | 98 | ||
| 99 | + var findfoods; | ||
| 28 | // request log | 100 | // request log |
| 29 | console.log('======================', new Date() ,'======================'); | 101 | console.log('======================', new Date() ,'======================'); |
| 30 | console.log('[request]', req.body); | 102 | console.log('[request]', req.body); |
| 31 | console.log('[request source] ', eventObj.source); | 103 | console.log('[request source] ', eventObj.source); |
| 32 | console.log('[request message]', eventObj.message); | 104 | console.log('[request message]', eventObj.message); |
| 105 | + text = hello(text1); | ||
| 106 | + | ||
| 107 | + if(text == true){ | ||
| 108 | + console.log('Hi',message); | ||
| 109 | + hello(text2); | ||
| 110 | + } | ||
| 111 | + inputfood(eventObj); | ||
| 112 | + | ||
| 113 | + findfoods = findfood(message.text); | ||
| 114 | + if(findfoods ==true){ | ||
| 115 | + console.log('음식을 찾았습니다.'); | ||
| 116 | + printinformation(findfoods); | ||
| 117 | + } | ||
| 118 | + | ||
| 33 | 119 | ||
| 34 | - getfoodinfo(eventObj.replyToken, eventObj.message.text); // eventObj.message.text 로 pc_kor_nm 받기 | ||
| 35 | 120 | ||
| 36 | 121 | ||
| 37 | - res.sendStatus(200); | 122 | + |
| 123 | + | ||
| 124 | + | ||
| 125 | + //getfoodinfo(eventObj.replyToken, eventObj.message.text); // eventObj.message.text 로 pc_kor_nm 받기 | ||
| 126 | + | ||
| 127 | + | ||
| 128 | + //res.sendStatus(200); | ||
| 38 | }); | 129 | }); |
| 39 | 130 | ||
| 131 | +/* | ||
| 40 | function getfoodinfo(replyToken, kor_name) { | 132 | function getfoodinfo(replyToken, kor_name) { |
| 41 | 133 | ||
| 42 | request.post( | 134 | request.post( |
| ... | @@ -88,7 +180,7 @@ function getfoodinfo(replyToken, kor_name) { | ... | @@ -88,7 +180,7 @@ function getfoodinfo(replyToken, kor_name) { |
| 88 | }); | 180 | }); |
| 89 | 181 | ||
| 90 | } | 182 | } |
| 91 | - | 183 | +*/ |
| 92 | try { | 184 | try { |
| 93 | const option = { | 185 | const option = { |
| 94 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 186 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment