Showing
1 changed file
with
0 additions
and
88 deletions
trans/trans.js
deleted
100644 → 0
1 | -const request = require('request'); | ||
2 | -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
3 | -const TOKEN = 'LFi+FvOOFOydz0EKN22WRnQyiilnEiyxe2HVV1WrI54Jnght6+Gga07m7pxqSQltBJG2AV2lYnYOAk4TqxzZFKW9R36CJcQs+NaNEiNKJtgBfT/t3tEta/J6GtXxGz/DqdHnfZqSSfLFpXzun/ITTwdB04t89/1O/w1cDnyilFU=' | ||
4 | -const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | ||
5 | -const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb' | ||
6 | -const PAPAGO_SECRET = 'Wdz2tudrzB' | ||
7 | -const fs = require('fs'); | ||
8 | -const path = require('path'); | ||
9 | -const HTTPS = require('https'); | ||
10 | -const domain = "www.chatbotshin.tk" | ||
11 | -const sslport = 23023; | ||
12 | -const bodyParser = require('body-parser'); | ||
13 | - | ||
14 | -//-----target language verification-------------- | ||
15 | -var trans_dest = 'target=en'; // defualt = english | ||
16 | -var trans_trigger = 0; | ||
17 | -//----------------------------------------------- | ||
18 | - | ||
19 | -// language identification & translation | ||
20 | -function trans_lng_selector(message){ | ||
21 | - if(message=='/번역 영어' || message=='/번역 프랑스어' || message=='/번역 일본어'){ | ||
22 | - //trans_trigger = 0 or 1; | ||
23 | - trans_change(message); | ||
24 | - trans_trigger = 1; | ||
25 | - console.log('[trans_dest]', trans_dest); | ||
26 | - return trans_trigger; | ||
27 | - } | ||
28 | -} | ||
29 | - | ||
30 | - | ||
31 | - | ||
32 | -function translating(replyToken, message) { | ||
33 | - | ||
34 | - request.post( | ||
35 | - { | ||
36 | - url: PAPAGO_URL, | ||
37 | - headers: { | ||
38 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
39 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
40 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
41 | - }, | ||
42 | - body: 'source=ko&' + trans_dest + '&text=' + message, | ||
43 | - json:true | ||
44 | - },(error, response, body) => { | ||
45 | - if(!error && response.statusCode == 200) { | ||
46 | - console.log(body.message); | ||
47 | - var transMessage = body.message.result.translatedText; | ||
48 | - request.post( | ||
49 | - { | ||
50 | - url: TARGET_URL, | ||
51 | - headers: { | ||
52 | - 'Authorization': `Bearer ${TOKEN}` | ||
53 | - }, | ||
54 | - json: { | ||
55 | - "replyToken":replyToken, | ||
56 | - "messages":[ | ||
57 | - { | ||
58 | - "type":"text", | ||
59 | - "text":transMessage | ||
60 | - } | ||
61 | - ] | ||
62 | - } | ||
63 | - },(error, response, body) => { | ||
64 | - console.log(body) | ||
65 | - trans_trigger=0; | ||
66 | - return trans_trigger; | ||
67 | - }); | ||
68 | - } | ||
69 | - }); | ||
70 | - | ||
71 | -} | ||
72 | - | ||
73 | -// language index identification | ||
74 | -function trans_change(index){ | ||
75 | - if(index == '/번역 영어'){ | ||
76 | - trans_dest = 'target=en'; | ||
77 | - } | ||
78 | - else if(index == '/번역 일본어'){ | ||
79 | - trans_dest = 'target=ja'; | ||
80 | - } | ||
81 | - else if(index == '/번역 프랑스어'){ | ||
82 | - trans_dest = 'target=fr'; | ||
83 | - } | ||
84 | -} | ||
85 | - | ||
86 | -module.exports.translating = translating; | ||
87 | -module.exports.trans_lng_selector = trans_lng_selector; | ||
88 | -module.exports.trans_change = trans_change; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment