Showing
1 changed file
with
38 additions
and
11 deletions
... | @@ -11,9 +11,10 @@ const bodyParser = require('body-parser'); | ... | @@ -11,9 +11,10 @@ const bodyParser = require('body-parser'); |
11 | var app = express(); | 11 | var app = express(); |
12 | const { info } = require('console'); | 12 | const { info } = require('console'); |
13 | 13 | ||
14 | -var PythonShell = require('python-shell'); | 14 | +var { PythonShell } = require('python-shell'); |
15 | +var pyshell = new PythonShell('weather_chat.py'); | ||
15 | 16 | ||
16 | -var options = { | 17 | +let options = { |
17 | mode: 'text', | 18 | mode: 'text', |
18 | pythonPath: '', | 19 | pythonPath: '', |
19 | pythonOptions: ['-u'], | 20 | pythonOptions: ['-u'], |
... | @@ -41,11 +42,8 @@ app.post('/hook', function (req, res) { | ... | @@ -41,11 +42,8 @@ app.post('/hook', function (req, res) { |
41 | else if(eventObj.message.text == "이용방법") { | 42 | else if(eventObj.message.text == "이용방법") { |
42 | chatUse(eventObj.replyToken); | 43 | chatUse(eventObj.replyToken); |
43 | } | 44 | } |
44 | - else if(eventObj.message.text == "오늘의 날씨는") { | 45 | + else if(eventObj.message.text == "오늘의 날씨는?") { |
45 | - PythonShell.run('weather_chat.py', options, function(err, results) { | 46 | + chatWeather(eventObj.replyToken); |
46 | - if(err) throw err; | ||
47 | - console.log('results: %j', results); | ||
48 | - }); | ||
49 | } | 47 | } |
50 | else { | 48 | else { |
51 | chatWrong(eventObj.replyToken); | 49 | chatWrong(eventObj.replyToken); |
... | @@ -66,7 +64,7 @@ function chatInfo(replyToken){ | ... | @@ -66,7 +64,7 @@ function chatInfo(replyToken){ |
66 | "messages":[ | 64 | "messages":[ |
67 | { | 65 | { |
68 | "type":"text", | 66 | "type":"text", |
69 | - "text":"서울 지역의 날씨와 기온에 따른 옷차림새를 추천해줍니다." | 67 | + "text":"서울 지역의 오늘의 날씨와 기온에 따른 옷차림새를 추천해줍니다." |
70 | } | 68 | } |
71 | ] | 69 | ] |
72 | } | 70 | } |
... | @@ -87,7 +85,7 @@ function chatUse(replyToken){ | ... | @@ -87,7 +85,7 @@ function chatUse(replyToken){ |
87 | "messages":[ | 85 | "messages":[ |
88 | { | 86 | { |
89 | "type":"text", | 87 | "type":"text", |
90 | - "text":"오늘의 날씨는? 을 똑같이\n 입력해주시면 작동합니다." | 88 | + "text":"오늘의 날씨는? 을 똑같이\n입력해주시면 작동합니다." |
91 | } | 89 | } |
92 | ] | 90 | ] |
93 | } | 91 | } |
... | @@ -96,7 +94,15 @@ function chatUse(replyToken){ | ... | @@ -96,7 +94,15 @@ function chatUse(replyToken){ |
96 | }); | 94 | }); |
97 | } | 95 | } |
98 | 96 | ||
99 | -function chatWrong(replyToken){ | 97 | +function chatWeather(replyToken){ |
98 | + var PM = " "; | ||
99 | + | ||
100 | + pyshell.send('request') | ||
101 | + pyshell.on('message', function(data){ | ||
102 | + console.log(data); | ||
103 | + PM = data; | ||
104 | + }); | ||
105 | + | ||
100 | request.post( | 106 | request.post( |
101 | { | 107 | { |
102 | url: TARGET_URL, | 108 | url: TARGET_URL, |
... | @@ -108,7 +114,7 @@ function chatWrong(replyToken){ | ... | @@ -108,7 +114,7 @@ function chatWrong(replyToken){ |
108 | "messages":[ | 114 | "messages":[ |
109 | { | 115 | { |
110 | "type":"text", | 116 | "type":"text", |
111 | - "text":"잘못된 입력입니다.\n '이용방법' 혹은 '오늘의 날씨는?'을 입력해주세요." | 117 | + "text": PM |
112 | } | 118 | } |
113 | ] | 119 | ] |
114 | } | 120 | } |
... | @@ -117,6 +123,27 @@ function chatWrong(replyToken){ | ... | @@ -117,6 +123,27 @@ function chatWrong(replyToken){ |
117 | }); | 123 | }); |
118 | } | 124 | } |
119 | 125 | ||
126 | +function chatWrong(replyToken){ | ||
127 | + request.post( | ||
128 | + { | ||
129 | + url: TARGET_URL, | ||
130 | + headers: { | ||
131 | + 'Authorization': `Bearer ${TOKEN}` | ||
132 | + }, | ||
133 | + json: { | ||
134 | + "replyToken":replyToken, | ||
135 | + "messages":[ | ||
136 | + { | ||
137 | + "type":"text", | ||
138 | + "text":"잘못된 입력입니다.\n'설명', '이용방법', '오늘의 날씨는?' \n중 하나를 입력해주세요." | ||
139 | + } | ||
140 | + ] | ||
141 | + } | ||
142 | + },(error, response, body) => { | ||
143 | + console.log(body) | ||
144 | + }); | ||
145 | +} | ||
146 | + | ||
120 | try { | 147 | try { |
121 | const option = { | 148 | const option = { |
122 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 149 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment