Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신일섭
/
ShoppingCart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
4
Network
Create a new issue
Commits
Issue Boards
Authored by
신일섭
2020-06-04 23:36:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b79f14d5286f640df509629e5483bde5e74de328
b79f14d5
1 parent
ee01d17e
번역기 모듈 분리
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
trans/trans.js
trans/trans.js
0 → 100644
View file @
b79f14d
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'LFi+FvOOFOydz0EKN22WRnQyiilnEiyxe2HVV1WrI54Jnght6+Gga07m7pxqSQltBJG2AV2lYnYOAk4TqxzZFKW9R36CJcQs+NaNEiNKJtgBfT/t3tEta/J6GtXxGz/DqdHnfZqSSfLFpXzun/ITTwdB04t89/1O/w1cDnyilFU='
const
PAPAGO_URL
=
'https://openapi.naver.com/v1/papago/n2mt'
const
PAPAGO_ID
=
'r_kuebFKCqBeL3SI_dFb'
const
PAPAGO_SECRET
=
'Wdz2tudrzB'
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"www.chatbotshin.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
// language identification & translation
function
trans_lng_selector
(){
if
(
eventObj
.
message
.
text
==
'/번역 영어'
||
eventObj
.
message
.
text
==
'/번역 프랑스어'
||
eventObj
.
message
.
text
==
'/번역 일본어'
){
//trans_trigger = 0 or 1;
trans_change
(
eventObj
.
message
.
text
);
trans_trigger
=
1
;
console
.
log
(
'[trans_dest]'
,
trans_dest
);
}
}
function
translating
(
replyToken
,
message
)
{
request
.
post
(
{
url
:
PAPAGO_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-Naver-Client-Id'
:
`
${
PAPAGO_ID
}
`
,
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
body
:
'source=ko&'
+
trans_dest
+
'&text='
+
message
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
body
.
message
);
var
transMessage
=
body
.
message
.
result
.
translatedText
;
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
transMessage
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
// language index identification
function
trans_change
(
index
){
if
(
index
==
'/번역 영어'
){
trans_dest
=
'target=en'
;
}
else
if
(
index
==
'/번역 일본어'
){
trans_dest
=
'target=ja'
;
}
else
if
(
index
==
'/번역 프랑스어'
){
trans_dest
=
'target=fr'
;
}
}
module
.
exports
.
translating
=
translating
;
module
.
exports
.
trans_lng_selector
=
trans_lng_selector
;
module
.
exports
.
trans_change
=
trans_change
;
\ No newline at end of file
Please
register
or
login
to post a comment