신일섭

번역기 define error 해결

......@@ -16,6 +16,7 @@ const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb'
const PAPAGO_SECRET = 'Wdz2tudrzB'
var trans = require('./trans/trans')
var trans_counter = 0;
//-----------------------------------------------------------
const fs = require('fs');
......@@ -25,10 +26,7 @@ const domain = "www.chatbotshin.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
//-----target language verification--------------
var trans_dest = 'target=en'; // defualt = english
var trans_trigger = 0;
//-----------------------------------------------
var app = express();
......@@ -51,12 +49,13 @@ app.post('/hook', function (req, res) {
console.log('[request message]', eventObj.message);
//----------------------------------------------------------------------------
// language identification & translation
if(eventObj.message.text.indexOf('/번역')){
trans.trans_lng_selector(); // trans_trigger -> 1
//--------------------language identification & translation-------------------
if(eventObj.message.text.includes('/번역')){
console.log('번역캐치: ', eventObj.message.text);
trans_counter = trans.trans_lng_selector(eventObj.message.text); // after this trans_trigger = 1
}
else if(trans_trigger==1){
translating(eventObj.replyToken, eventObj.message.text);
else if(trans_counter==1){
trans_counter = trans.translating(eventObj.replyToken, eventObj.message.text); // after this trans_trigger = 0
}
......
......@@ -11,14 +11,19 @@ const domain = "www.chatbotshin.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
//-----target language verification--------------
var trans_dest = 'target=en'; // defualt = english
var trans_trigger = 0;
//-----------------------------------------------
// language identification & translation
function trans_lng_selector(){
if(eventObj.message.text=='/번역 영어' || eventObj.message.text=='/번역 프랑스어' || eventObj.message.text=='/번역 일본어'){
function trans_lng_selector(message){
if(message=='/번역 영어' || message=='/번역 프랑스어' || message=='/번역 일본어'){
//trans_trigger = 0 or 1;
trans_change(eventObj.message.text);
trans_change(message);
trans_trigger = 1;
console.log('[trans_dest]', trans_dest);
return trans_trigger;
}
}
......@@ -57,6 +62,8 @@ function translating(replyToken, message) {
}
},(error, response, body) => {
console.log(body)
trans_trigger=0;
return trans_trigger;
});
}
});
......