김대욱

new

......@@ -17,31 +17,23 @@ app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var kind = eventObj.kind;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request kind] ', eventObj.kind);
console.log('[request message]', eventObj.message);
if(message == "영어"){
transen(eventObj.replyToken, eventObj.message.text);
}
else if(message == "일본어"){
transja(eventObj.replyToken, eventObj.message.text);
}
else if(message == "프랑스어"){
transfr(eventObj.replyToken, eventObj.message.text);
}
trans(eventObj.replyToken, eventObj.kind, eventObj.message.text);
res.sendStatus(200);
});
function transen(replyToken, message) {
function trans(replyToken, kind, message) {
if(kind == "영어"){
request.post(
{
url: PAPAGO_URL,
......@@ -76,10 +68,8 @@ function transen(replyToken, message) {
});
}
});
}
function transfr(replyToken, message) {
}
else if(kind == "일본어"){
request.post(
{
url: PAPAGO_URL,
......@@ -88,7 +78,7 @@ function transfr(replyToken, message) {
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=ko&target=fr&text=' + message,
body: 'source=ko&target=ja&text=' + message,
json:true
},(error, response, body) => {
if(!error && response.statusCode == 200) {
......@@ -114,10 +104,8 @@ function transfr(replyToken, message) {
});
}
});
}
function transja(replyToken, message) {
}
else if(kind == "프랑스어"){
request.post(
{
url: PAPAGO_URL,
......@@ -126,7 +114,7 @@ function transja(replyToken, message) {
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=ko&target=ja&text=' + message,
body: 'source=ko&target=fr&text=' + message,
json:true
},(error, response, body) => {
if(!error && response.statusCode == 200) {
......@@ -152,7 +140,7 @@ function transja(replyToken, message) {
});
}
});
}
}
try {
......