Showing
1 changed file
with
46 additions
and
7 deletions
... | @@ -3,6 +3,7 @@ const request = require('request'); | ... | @@ -3,6 +3,7 @@ const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | const TOKEN = 'm79m/yBsTVzZeC9pYqSLzEL00Hp0HqsVE/0ZsZxW2HNAwdnb9TwDgBcOyCn3/aJASXsE8ekpyGg4Gts/4r8LO72OTZec9Np5Mh9g1vrgyDj5theWv4g2miE5F1Cqax4X3waj1aIzDGHcUZdHD6fQvAdB04t89/1O/w1cDnyilFU=' | 4 | const TOKEN = 'm79m/yBsTVzZeC9pYqSLzEL00Hp0HqsVE/0ZsZxW2HNAwdnb9TwDgBcOyCn3/aJASXsE8ekpyGg4Gts/4r8LO72OTZec9Np5Mh9g1vrgyDj5theWv4g2miE5F1Cqax4X3waj1aIzDGHcUZdHD6fQvAdB04t89/1O/w1cDnyilFU=' |
5 | const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | 5 | const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' |
6 | +const PAPAGO_D_URL = 'https://openapi.naver.com/v1/papago/detectLangs' | ||
6 | const PAPAGO_ID = 'tA41WEd_nbzy0nZcUQks' | 7 | const PAPAGO_ID = 'tA41WEd_nbzy0nZcUQks' |
7 | const PAPAGO_SECRET = '6DHwov9gg2' | 8 | const PAPAGO_SECRET = '6DHwov9gg2' |
8 | // const fs = require('fs'); | 9 | // const fs = require('fs'); |
... | @@ -14,7 +15,9 @@ const bodyParser = require('body-parser'); | ... | @@ -14,7 +15,9 @@ const bodyParser = require('body-parser'); |
14 | var app = express(); | 15 | var app = express(); |
15 | 16 | ||
16 | var ln = 'en'; //default value en | 17 | var ln = 'en'; //default value en |
18 | +var tempc = 'ko'; | ||
17 | var lnDetec = new Array(); | 19 | var lnDetec = new Array(); |
20 | +var userinfo = new Array(); | ||
18 | lnDetec[0] = | 21 | lnDetec[0] = |
19 | { | 22 | { |
20 | "InLn" : '영어', | 23 | "InLn" : '영어', |
... | @@ -31,6 +34,14 @@ lnDetec[2] = | ... | @@ -31,6 +34,14 @@ lnDetec[2] = |
31 | "PaLn" : 'fr' | 34 | "PaLn" : 'fr' |
32 | } | 35 | } |
33 | 36 | ||
37 | +userinfo[0] = | ||
38 | +{ | ||
39 | + userId : 'userId', | ||
40 | + userInLn : 'userInLn', | ||
41 | + userPaLn : 'userPaLn' | ||
42 | +} | ||
43 | + | ||
44 | + | ||
34 | app.use(bodyParser.json()); | 45 | app.use(bodyParser.json()); |
35 | app.post('/hook', function (req, res) { | 46 | app.post('/hook', function (req, res) { |
36 | 47 | ||
... | @@ -44,7 +55,7 @@ app.post('/hook', function (req, res) { | ... | @@ -44,7 +55,7 @@ app.post('/hook', function (req, res) { |
44 | // console.log('======================', new Date() ,'======================'); | 55 | // console.log('======================', new Date() ,'======================'); |
45 | // console.log('[request]', req.body); | 56 | // console.log('[request]', req.body); |
46 | // console.log('[request source] ', eventObj.source); | 57 | // console.log('[request source] ', eventObj.source); |
47 | - console.log('userId? ', eventObj.source.userId); | 58 | + console.log('userId: ', eventObj.source.userId); |
48 | // console.log('[request message]', eventObj.message); | 59 | // console.log('[request message]', eventObj.message); |
49 | // console.log('my meesage: ', message.text); | 60 | // console.log('my meesage: ', message.text); |
50 | // console.log('my ip check: ', req.ip); | 61 | // console.log('my ip check: ', req.ip); |
... | @@ -57,13 +68,16 @@ app.post('/hook', function (req, res) { | ... | @@ -57,13 +68,16 @@ app.post('/hook', function (req, res) { |
57 | LnCh = 0; | 68 | LnCh = 0; |
58 | } | 69 | } |
59 | } | 70 | } |
60 | - if(LnCh) // if there is no attempt to change language then call trans() operator | ||
61 | - trans(eventObj.replyToken, eventObj.message.text, ln); | ||
62 | 71 | ||
72 | + if(LnCh) // if there is no attempt to change language then call operators | ||
73 | + { | ||
74 | + detector(message.text); | ||
75 | + trans(eventObj.replyToken, eventObj.message.text); | ||
76 | + } | ||
63 | res.sendStatus(200); | 77 | res.sendStatus(200); |
64 | }); | 78 | }); |
65 | 79 | ||
66 | -function trans(replyToken, message, ln) { | 80 | +function trans(replyToken, message) { |
67 | 81 | ||
68 | request.post( | 82 | request.post( |
69 | { | 83 | { |
... | @@ -73,12 +87,12 @@ function trans(replyToken, message, ln) { | ... | @@ -73,12 +87,12 @@ function trans(replyToken, message, ln) { |
73 | 'X-Naver-Client-Id': `${PAPAGO_ID}`, | 87 | 'X-Naver-Client-Id': `${PAPAGO_ID}`, |
74 | 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | 88 | 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` |
75 | }, | 89 | }, |
76 | - body: 'source=ko&target='+ln+'&text=' + message, | 90 | + //body: 'source=ko&target='+ln+'&text=' + message, |
77 | - //body: 'source=ko&target=en&text=' + message, | 91 | + body: 'source='+tempc+'&target='+ln+'&text='+message, |
78 | json:true | 92 | json:true |
79 | },(error, response, body) => { | 93 | },(error, response, body) => { |
80 | if(!error && response.statusCode == 200) { | 94 | if(!error && response.statusCode == 200) { |
81 | - console.log(body.message); | 95 | + console.log('[객체 정보 확인]',body.message); |
82 | var transMessage = body.message.result.translatedText; | 96 | var transMessage = body.message.result.translatedText; |
83 | request.post( | 97 | request.post( |
84 | { | 98 | { |
... | @@ -103,6 +117,31 @@ function trans(replyToken, message, ln) { | ... | @@ -103,6 +117,31 @@ function trans(replyToken, message, ln) { |
103 | 117 | ||
104 | } | 118 | } |
105 | 119 | ||
120 | +function detector(message) | ||
121 | +{ | ||
122 | + request.post | ||
123 | + ( | ||
124 | + { | ||
125 | + url: PAPAGO_D_URL, | ||
126 | + headers: | ||
127 | + { | ||
128 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
129 | + 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
130 | + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
131 | + }, | ||
132 | + body: 'query='+message, | ||
133 | + json:true | ||
134 | + },(error, response, body) => | ||
135 | + { | ||
136 | + if(!error && response.statusCode == 200) | ||
137 | + { | ||
138 | + console.log('[넘어온 메시지]', message); | ||
139 | + console.log('[객체 정보 확인]',body); | ||
140 | + tempc = body.langCode; | ||
141 | + } | ||
142 | + } | ||
143 | + ) | ||
144 | +} | ||
106 | // try { | 145 | // try { |
107 | // const option = { | 146 | // const option = { |
108 | // ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 147 | // ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment