Showing
1 changed file
with
39 additions
and
112 deletions
... | @@ -17,130 +17,57 @@ app.post('/hook', function (req, res) { | ... | @@ -17,130 +17,57 @@ app.post('/hook', function (req, res) { |
17 | 17 | ||
18 | var eventObj = req.body.events[0]; | 18 | var eventObj = req.body.events[0]; |
19 | var source = eventObj.source; | 19 | var source = eventObj.source; |
20 | - var kind = eventObj.kind; | ||
21 | var message = eventObj.message; | 20 | var message = eventObj.message; |
22 | 21 | ||
23 | // request log | 22 | // request log |
24 | console.log('======================', new Date() ,'======================'); | 23 | console.log('======================', new Date() ,'======================'); |
25 | console.log('[request]', req.body); | 24 | console.log('[request]', req.body); |
26 | console.log('[request source] ', eventObj.source); | 25 | console.log('[request source] ', eventObj.source); |
27 | - console.log('[request kind] ', eventObj.kind); | ||
28 | console.log('[request message]', eventObj.message); | 26 | console.log('[request message]', eventObj.message); |
27 | + | ||
28 | + trans(eventObj.replyToken, eventObj.message.text); | ||
29 | 29 | ||
30 | - trans(eventObj.replyToken, eventObj.kind.text, eventObj.message.text); | ||
31 | 30 | ||
32 | res.sendStatus(200); | 31 | res.sendStatus(200); |
33 | }); | 32 | }); |
34 | 33 | ||
35 | -function trans(replyToken, kind, message) { | 34 | +function trans(replyToken, message) { |
36 | - if(kind == "영어"){ | 35 | + |
37 | - request.post( | 36 | + request.post( |
38 | - { | 37 | + { |
39 | - url: PAPAGO_URL, | 38 | + url: PAPAGO_URL, |
40 | - headers: { | 39 | + headers: { |
41 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | 40 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', |
42 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | 41 | + 'X-Naver-Client-Id': `${PAPAGO_ID}`, |
43 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | 42 | + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` |
44 | - }, | 43 | + }, |
45 | - body: 'source=ko&target=en&text=' + message, | 44 | + body: 'source=ko&target=en&text=' + message, |
46 | - json:true | 45 | + json:true |
47 | - },(error, response, body) => { | 46 | + },(error, response, body) => { |
48 | - if(!error && response.statusCode == 200) { | 47 | + if(!error && response.statusCode == 200) { |
49 | - console.log(body.message); | 48 | + console.log(body.message); |
50 | - var transMessage = body.message.result.translatedText; | 49 | + var transMessage = body.message.result.translatedText; |
51 | - request.post( | 50 | + request.post( |
52 | - { | 51 | + { |
53 | - url: TARGET_URL, | 52 | + url: TARGET_URL, |
54 | - headers: { | 53 | + headers: { |
55 | - 'Authorization': `Bearer ${TOKEN}` | 54 | + 'Authorization': `Bearer ${TOKEN}` |
56 | - }, | 55 | + }, |
57 | - json: { | 56 | + json: { |
58 | - "replyToken":replyToken, | 57 | + "replyToken":replyToken, |
59 | - "messages":[ | 58 | + "messages":[ |
60 | - { | 59 | + { |
61 | - "type":"text", | 60 | + "type":"text", |
62 | - "text":transMessage | 61 | + "text":transMessage |
63 | - } | 62 | + } |
64 | - ] | 63 | + ] |
65 | - } | 64 | + } |
66 | - },(error, response, body) => { | 65 | + },(error, response, body) => { |
67 | - console.log(body) | 66 | + console.log(body) |
68 | - }); | 67 | + }); |
69 | - } | 68 | + } |
70 | - }); | 69 | + }); |
71 | - } | 70 | + |
72 | - else if(kind == "일본어"){ | ||
73 | - request.post( | ||
74 | - { | ||
75 | - url: PAPAGO_URL, | ||
76 | - headers: { | ||
77 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
78 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
79 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
80 | - }, | ||
81 | - body: 'source=ko&target=ja&text=' + message, | ||
82 | - json:true | ||
83 | - },(error, response, body) => { | ||
84 | - if(!error && response.statusCode == 200) { | ||
85 | - console.log(body.message); | ||
86 | - var transMessage = body.message.result.translatedText; | ||
87 | - request.post( | ||
88 | - { | ||
89 | - url: TARGET_URL, | ||
90 | - headers: { | ||
91 | - 'Authorization': `Bearer ${TOKEN}` | ||
92 | - }, | ||
93 | - json: { | ||
94 | - "replyToken":replyToken, | ||
95 | - "messages":[ | ||
96 | - { | ||
97 | - "type":"text", | ||
98 | - "text":transMessage | ||
99 | - } | ||
100 | - ] | ||
101 | - } | ||
102 | - },(error, response, body) => { | ||
103 | - console.log(body) | ||
104 | - }); | ||
105 | - } | ||
106 | - }); | ||
107 | - } | ||
108 | - else if(kind == "프랑스어"){ | ||
109 | - request.post( | ||
110 | - { | ||
111 | - url: PAPAGO_URL, | ||
112 | - headers: { | ||
113 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
114 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
115 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
116 | - }, | ||
117 | - body: 'source=ko&target=fr&text=' + message, | ||
118 | - json:true | ||
119 | - },(error, response, body) => { | ||
120 | - if(!error && response.statusCode == 200) { | ||
121 | - console.log(body.message); | ||
122 | - var transMessage = body.message.result.translatedText; | ||
123 | - request.post( | ||
124 | - { | ||
125 | - url: TARGET_URL, | ||
126 | - headers: { | ||
127 | - 'Authorization': `Bearer ${TOKEN}` | ||
128 | - }, | ||
129 | - json: { | ||
130 | - "replyToken":replyToken, | ||
131 | - "messages":[ | ||
132 | - { | ||
133 | - "type":"text", | ||
134 | - "text":transMessage | ||
135 | - } | ||
136 | - ] | ||
137 | - } | ||
138 | - },(error, response, body) => { | ||
139 | - console.log(body) | ||
140 | - }); | ||
141 | - } | ||
142 | - }); | ||
143 | - } | ||
144 | } | 71 | } |
145 | 72 | ||
146 | try { | 73 | try { | ... | ... |
-
Please register or login to post a comment