Showing
1 changed file
with
94 additions
and
37 deletions
... | @@ -10,58 +10,115 @@ const sslport = 23023; | ... | @@ -10,58 +10,115 @@ const sslport = 23023; |
10 | 10 | ||
11 | const bodyParser = require('body-parser'); | 11 | const bodyParser = require('body-parser'); |
12 | var app = express(); | 12 | var app = express(); |
13 | + | ||
14 | + | ||
15 | + | ||
16 | + | ||
13 | app.use(bodyParser.json()); | 17 | app.use(bodyParser.json()); |
14 | app.post('/hook', function (req, res) { | 18 | app.post('/hook', function (req, res) { |
15 | 19 | ||
16 | var eventObj = req.body.events[0]; | 20 | var eventObj = req.body.events[0]; |
17 | var source = eventObj.source; | 21 | var source = eventObj.source; |
18 | - | ||
19 | var message = eventObj.message; | 22 | var message = eventObj.message; |
20 | - var pystring; | 23 | + // request log |
24 | + console.log('======================', new Date() ,'======================'); | ||
25 | + console.log('[request]', req.body); | ||
26 | + console.log('[request source] ', eventObj.source); | ||
27 | + console.log('[request message]', eventObj.message); | ||
28 | + | ||
29 | + basicinform(eventObj.replyToken, eventObj.message.text) | ||
21 | 30 | ||
31 | + res.sendStatus(200); | ||
32 | + | ||
33 | +}); | ||
34 | + | ||
35 | +function basicinform(replyToken, message) { | ||
36 | + | ||
37 | + var pystring; | ||
22 | const spawn = require("child_process").spawn; | 38 | const spawn = require("child_process").spawn; |
23 | - const process = spawn("python", ["basic.py", eventObj.message.text]); | 39 | + const process = spawn("python", ["basic.py", message]); |
24 | const Callback = (data) => { | 40 | const Callback = (data) => { |
25 | console.log("Data :", data.toString()); | 41 | console.log("Data :", data.toString()); |
26 | pystring = data.toString(); | 42 | pystring = data.toString(); |
27 | - // request log | 43 | + if(pystring[0] == '1') |
28 | - console.log('======================', new Date() ,'======================'); | 44 | + { |
29 | - console.log('[request]', req.body); | 45 | + pystring = pystring.replace('1현', '현'); |
30 | - console.log('[request source] ', eventObj.source); | 46 | + request.post( |
31 | - console.log('[request message]', eventObj.message); | 47 | + { |
32 | - | 48 | + url: TARGET_URL, |
33 | - request.post( | 49 | + headers: { |
34 | - { | 50 | + 'Authorization': `Bearer ${TOKEN}` |
35 | - url: TARGET_URL, | 51 | + }, |
36 | - headers: { | 52 | + json: { |
37 | - 'Authorization': `Bearer ${TOKEN}` | 53 | + "replyToken":replyToken, |
38 | - }, | 54 | + "messages":[ |
39 | - json: { | 55 | + { |
40 | - "replyToken":eventObj.replyToken, | 56 | + "type":"text", |
41 | - "messages":[ | 57 | + "text":pystring |
42 | - { | 58 | + } |
43 | - "type":"text", | 59 | + ] |
44 | - "text":pystring | 60 | + } |
45 | - }, | 61 | + },(error, response, body) => { |
46 | - { | 62 | + console.log(body) |
47 | - "type":"text", | 63 | + }); |
48 | - "text":"May I help you?" | 64 | + } |
49 | - } | 65 | + else |
50 | - ] | 66 | + { |
51 | - } | 67 | + var candarr = pystring.split('\n') |
52 | - },(error, response, body) => { | 68 | + request.post( |
53 | - console.log(body) | 69 | + { |
54 | - }); | 70 | + url: TARGET_URL, |
55 | - | 71 | + headers: { |
72 | + 'Authorization': `Bearer ${TOKEN}` | ||
73 | + }, | ||
74 | + json: { | ||
75 | + "replyToken":replyToken, | ||
76 | + "messages":[ | ||
77 | + { | ||
78 | + "type": "text", | ||
79 | + "text": pystring, | ||
80 | + "quickReply": { | ||
81 | + "items": [ | ||
82 | + { | ||
83 | + "type": "action", | ||
84 | + "action": { | ||
85 | + "type": "message", | ||
86 | + "label": candarr[0], | ||
87 | + "text": candarr[0] | ||
88 | + } | ||
89 | + }, | ||
90 | + { | ||
91 | + "type": "action", | ||
92 | + "action": { | ||
93 | + "type": "message", | ||
94 | + "label": candarr[1], | ||
95 | + "text": candarr[1] | ||
96 | + } | ||
97 | + }, | ||
98 | + { | ||
99 | + "type": "action", | ||
100 | + "action": { | ||
101 | + "type": "message", | ||
102 | + "label": candarr[2], | ||
103 | + "text": candarr[2] | ||
104 | + } | ||
105 | + } | ||
106 | + ] | ||
107 | + } | ||
108 | + } | ||
109 | + ] | ||
110 | + | ||
111 | + } | ||
112 | + },(error, response, body) => { | ||
113 | + console.log(body) | ||
114 | + }); | ||
115 | + } | ||
116 | + | ||
56 | 117 | ||
57 | - res.sendStatus(200); | ||
58 | 118 | ||
59 | }; | 119 | }; |
60 | process.stdout.on("data", Callback); | 120 | process.stdout.on("data", Callback); |
61 | - | 121 | +} |
62 | - | ||
63 | - | ||
64 | -}); | ||
65 | 122 | ||
66 | try { | 123 | try { |
67 | const option = { | 124 | const option = { | ... | ... |
-
Please register or login to post a comment