Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김영곤
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최원섭
2017-11-27 16:37:48 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
33e1f6a32b0218e58c1bc1d634f61318c069c0b7
33e1f6a3
1 parent
f1d7c66a
[Develop] Naver Papago SMT Translate Update
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
8 deletions
server.js
server.js
View file @
33e1f6a
var
request
=
require
(
'request'
);
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
var
api_url
=
'https://openapi.naver.com/v1/papago/n2mt'
;
var
client_id
=
'86rKmat0DijccSxKa01P'
;
var
client_secret
=
'rMapNjB8DP'
;
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
...
...
@@ -24,16 +29,41 @@ app.post('/message', function(req, res) {
};
console
.
log
(
_obj
.
content
)
let
massage
=
{
"message"
:
{
"text"
:
_obj
.
content
},
var
options
=
{
url
:
api_url
,
form
:
{
'source'
:
'ko'
,
'target'
:
'en'
,
'text'
:
req
.
body
.
content
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
request
.
post
(
options
,
function
(
error
,
response
,
body
){
if
(
!
error
&&
response
.
statusCode
==
200
){
var
objBody
=
JSON
.
parse
(
response
.
body
);
console
.
log
(
objBody
.
message
.
result
.
translatedText
);
let
massage
=
{
"message"
:
{
"text"
:
objBody
.
message
.
result
.
translatedText
},
};
res
.
set
({
'content-type'
:
'application/json'
}).
send
(
JSON
.
stringify
(
massage
));
res
.
set
({
'content-type'
:
'application/json'
}).
send
(
JSON
.
stringify
(
massage
));
}
else
{
res
.
status
(
response
.
statusCode
).
end
();
console
.
log
(
'error = '
+
response
.
statusCode
);
let
massage
=
{
"message"
:
{
"text"
:
response
.
statusCode
},
};
res
.
set
({
'content-type'
:
'application/json'
}).
send
(
JSON
.
stringify
(
massage
));
}
});
});
app
.
listen
(
80
,
function
(){
...
...
Please
register
or
login
to post a comment