김대욱

new

...@@ -17,31 +17,23 @@ app.post('/hook', function (req, res) { ...@@ -17,31 +17,23 @@ 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;
20 var message = eventObj.message; 21 var message = eventObj.message;
21 22
22 // request log 23 // request log
23 console.log('======================', new Date() ,'======================'); 24 console.log('======================', new Date() ,'======================');
24 console.log('[request]', req.body); 25 console.log('[request]', req.body);
25 console.log('[request source] ', eventObj.source); 26 console.log('[request source] ', eventObj.source);
27 + console.log('[request kind] ', eventObj.kind);
26 console.log('[request message]', eventObj.message); 28 console.log('[request message]', eventObj.message);
27 - if(message == "영어"){
28 - transen(eventObj.replyToken, eventObj.message.text);
29 - }
30 - else if(message == "일본어"){
31 - transja(eventObj.replyToken, eventObj.message.text);
32 - }
33 - else if(message == "프랑스어"){
34 - transfr(eventObj.replyToken, eventObj.message.text);
35 - }
36 -
37 -
38 29
30 + trans(eventObj.replyToken, eventObj.kind, eventObj.message.text);
39 31
40 res.sendStatus(200); 32 res.sendStatus(200);
41 }); 33 });
42 34
43 -function transen(replyToken, message) { 35 +function trans(replyToken, kind, message) {
44 - 36 + if(kind == "영어"){
45 request.post( 37 request.post(
46 { 38 {
47 url: PAPAGO_URL, 39 url: PAPAGO_URL,
...@@ -76,10 +68,8 @@ function transen(replyToken, message) { ...@@ -76,10 +68,8 @@ function transen(replyToken, message) {
76 }); 68 });
77 } 69 }
78 }); 70 });
79 - 71 + }
80 -} 72 + else if(kind == "일본어"){
81 -function transfr(replyToken, message) {
82 -
83 request.post( 73 request.post(
84 { 74 {
85 url: PAPAGO_URL, 75 url: PAPAGO_URL,
...@@ -88,7 +78,7 @@ function transfr(replyToken, message) { ...@@ -88,7 +78,7 @@ function transfr(replyToken, message) {
88 'X-Naver-Client-Id': `${PAPAGO_ID}`, 78 'X-Naver-Client-Id': `${PAPAGO_ID}`,
89 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 79 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
90 }, 80 },
91 - body: 'source=ko&target=fr&text=' + message, 81 + body: 'source=ko&target=ja&text=' + message,
92 json:true 82 json:true
93 },(error, response, body) => { 83 },(error, response, body) => {
94 if(!error && response.statusCode == 200) { 84 if(!error && response.statusCode == 200) {
...@@ -114,10 +104,8 @@ function transfr(replyToken, message) { ...@@ -114,10 +104,8 @@ function transfr(replyToken, message) {
114 }); 104 });
115 } 105 }
116 }); 106 });
117 - 107 + }
118 -} 108 + else if(kind == "프랑스어"){
119 -function transja(replyToken, message) {
120 -
121 request.post( 109 request.post(
122 { 110 {
123 url: PAPAGO_URL, 111 url: PAPAGO_URL,
...@@ -126,7 +114,7 @@ function transja(replyToken, message) { ...@@ -126,7 +114,7 @@ function transja(replyToken, message) {
126 'X-Naver-Client-Id': `${PAPAGO_ID}`, 114 'X-Naver-Client-Id': `${PAPAGO_ID}`,
127 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 115 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
128 }, 116 },
129 - body: 'source=ko&target=ja&text=' + message, 117 + body: 'source=ko&target=fr&text=' + message,
130 json:true 118 json:true
131 },(error, response, body) => { 119 },(error, response, body) => {
132 if(!error && response.statusCode == 200) { 120 if(!error && response.statusCode == 200) {
...@@ -152,7 +140,7 @@ function transja(replyToken, message) { ...@@ -152,7 +140,7 @@ function transja(replyToken, message) {
152 }); 140 });
153 } 141 }
154 }); 142 });
155 - 143 + }
156 } 144 }
157 145
158 try { 146 try {
......