신일섭

번역기 define error 해결

...@@ -16,6 +16,7 @@ const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' ...@@ -16,6 +16,7 @@ const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
16 const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb' 16 const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb'
17 const PAPAGO_SECRET = 'Wdz2tudrzB' 17 const PAPAGO_SECRET = 'Wdz2tudrzB'
18 var trans = require('./trans/trans') 18 var trans = require('./trans/trans')
19 +var trans_counter = 0;
19 //----------------------------------------------------------- 20 //-----------------------------------------------------------
20 21
21 const fs = require('fs'); 22 const fs = require('fs');
...@@ -25,10 +26,7 @@ const domain = "www.chatbotshin.tk" ...@@ -25,10 +26,7 @@ const domain = "www.chatbotshin.tk"
25 const sslport = 23023; 26 const sslport = 23023;
26 const bodyParser = require('body-parser'); 27 const bodyParser = require('body-parser');
27 28
28 -//-----target language verification-------------- 29 +
29 -var trans_dest = 'target=en'; // defualt = english
30 -var trans_trigger = 0;
31 -//-----------------------------------------------
32 30
33 var app = express(); 31 var app = express();
34 32
...@@ -51,12 +49,13 @@ app.post('/hook', function (req, res) { ...@@ -51,12 +49,13 @@ app.post('/hook', function (req, res) {
51 console.log('[request message]', eventObj.message); 49 console.log('[request message]', eventObj.message);
52 //---------------------------------------------------------------------------- 50 //----------------------------------------------------------------------------
53 51
54 - // language identification & translation 52 + //--------------------language identification & translation-------------------
55 - if(eventObj.message.text.indexOf('/번역')){ 53 + if(eventObj.message.text.includes('/번역')){
56 - trans.trans_lng_selector(); // trans_trigger -> 1 54 + console.log('번역캐치: ', eventObj.message.text);
55 + trans_counter = trans.trans_lng_selector(eventObj.message.text); // after this trans_trigger = 1
57 } 56 }
58 - else if(trans_trigger==1){ 57 + else if(trans_counter==1){
59 - translating(eventObj.replyToken, eventObj.message.text); 58 + trans_counter = trans.translating(eventObj.replyToken, eventObj.message.text); // after this trans_trigger = 0
60 } 59 }
61 60
62 61
......
...@@ -11,14 +11,19 @@ const domain = "www.chatbotshin.tk" ...@@ -11,14 +11,19 @@ const domain = "www.chatbotshin.tk"
11 const sslport = 23023; 11 const sslport = 23023;
12 const bodyParser = require('body-parser'); 12 const bodyParser = require('body-parser');
13 13
14 +//-----target language verification--------------
15 +var trans_dest = 'target=en'; // defualt = english
16 +var trans_trigger = 0;
17 +//-----------------------------------------------
14 18
15 // language identification & translation 19 // language identification & translation
16 -function trans_lng_selector(){ 20 +function trans_lng_selector(message){
17 - if(eventObj.message.text=='/번역 영어' || eventObj.message.text=='/번역 프랑스어' || eventObj.message.text=='/번역 일본어'){ 21 + if(message=='/번역 영어' || message=='/번역 프랑스어' || message=='/번역 일본어'){
18 //trans_trigger = 0 or 1; 22 //trans_trigger = 0 or 1;
19 - trans_change(eventObj.message.text); 23 + trans_change(message);
20 trans_trigger = 1; 24 trans_trigger = 1;
21 console.log('[trans_dest]', trans_dest); 25 console.log('[trans_dest]', trans_dest);
26 + return trans_trigger;
22 } 27 }
23 } 28 }
24 29
...@@ -57,6 +62,8 @@ function translating(replyToken, message) { ...@@ -57,6 +62,8 @@ function translating(replyToken, message) {
57 } 62 }
58 },(error, response, body) => { 63 },(error, response, body) => {
59 console.log(body) 64 console.log(body)
65 + trans_trigger=0;
66 + return trans_trigger;
60 }); 67 });
61 } 68 }
62 }); 69 });
......