Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2019-1-OpenSourceSW
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최원섭
2017-12-05 14:36:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c2ef91a034ec3c8a4f39d33a70706f4a357544e3
c2ef91a0
1 parent
10a8c0f0
[Develop] Translate Language Upgrade
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
7 deletions
routes/message.js
routes/message.js
View file @
c2ef91a
...
...
@@ -17,20 +17,92 @@ app.post('/', function(req, res) {
content
:
req
.
body
.
content
};
console
.
log
(
_obj
.
content
)
if
(
_obj
.
content
==
'/시작'
){
if
(
_obj
.
content
.
charAt
(
0
)
==
'/'
){
if
(
_obj
.
content
==
'/설정'
){
res
.
set
(
'content-type'
,
'application/json'
);
res
.
json
({
"message"
:
{
"text"
:
"언어를 선택하세요"
},
"keyboard"
:
{
"type"
:
"buttons"
,
"buttons"
:
[
"/한국어 -> 영어"
,
"/한국어 -> 일본어"
,
"/한국어 -> 중국어"
,
"/영어 -> 한국어"
,
"/일본어 -> 한국어"
,
"/중국어 -> 한국어"
]
}
});
}
else
if
(
_obj
.
content
==
'/시작'
){
res
.
json
({
"message"
:
{
"text"
:
"언어를 설정하고 싶으면 /설정 이라고 타이핑 해주세요"
},
"keyboard"
:
{
"type"
:
"text"
}
});
}
else
if
((
obj
.
content
==
'/한국어 -> 영어'
)
||
(
obj
.
content
==
'/한국어 -> 일본어'
)
||
(
obj
.
content
==
'/한국어 -> 중국어'
)
||
(
obj
.
content
==
'/영어 -> 한국어'
)
||
(
obj
.
content
==
'/일본어 -> 한국어'
)
||
(
obj
.
content
==
'중국어 -> 한국어'
)){
var
s1
=
choiceLanguage
(
content
.
split
(
"/"
)[
1
].
split
(
"->"
)[
0
]);
var
t1
=
choiceLanguage
(
content
.
split
(
"/"
)[
1
].
split
(
"->"
)[
1
]);
var
options
=
{
url
:
api_url
,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form
:
{
'source'
:
s1
,
'target'
:
t1
,
'text'
:
req
.
body
.
content
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
){
// Translate API Sucess
if
(
!
error
&&
response
.
statusCode
==
200
){
// JSON
var
objBody
=
JSON
.
parse
(
response
.
body
);
// Message 잘 찍히는지 확인
console
.
log
(
objBody
.
message
.
result
.
translatedText
);
// Kakao Message API
let
massage
=
{
"message"
:
{
// Naver API Translate 결과를 Kakao Message
"text"
:
objBody
.
message
.
result
.
translatedText
},
};
// Kakao Message API 전송
res
.
set
({
'content-type'
:
'application/json'
}).
send
(
JSON
.
stringify
(
massage
));
}
else
{
// Naver Message Error 발생
res
.
status
(
response
.
statusCode
).
end
();
console
.
log
(
'error = '
+
response
.
statusCode
);
let
massage
=
{
"message"
:
{
"text"
:
response
.
statusCode
},
};
// Kakao에 Error Message
res
.
set
({
'content-type'
:
'application/json'
}).
send
(
JSON
.
stringify
(
massage
));
}
});
}
else
{
res
.
set
(
'content-type'
,
'application/json'
);
res
.
json
({
"message"
:
{
"text"
:
"/기호가 들어간 명령어는 사용할 수 없습니다."
}
});
}
else
{
}
else
{
// Naver Papago Translate
var
options
=
{
url
:
api_url
,
...
...
@@ -38,7 +110,6 @@ else{
form
:
{
'source'
:
'ko'
,
'target'
:
'en'
,
'text'
:
req
.
body
.
content
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
console
.
log
(
'aa'
);
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
){
// Translate API Sucess
...
...
@@ -77,8 +148,22 @@ console.log('aa');
}).
send
(
JSON
.
stringify
(
massage
));
}
});
}
}
});
module
.
exports
=
app
;
function
choiceLanguage
(
str
)
{
if
(
str
==
"영어"
)
return
"en"
;
else
if
(
str
==
"한국어"
)
{
console
.
log
(
str
);
return
"ko"
;
}
else
if
(
str
==
"일본어"
)
return
"ja"
;
else
if
(
str
==
"중국어(간체)"
)
return
"zh-CN"
;
else
return
"ko"
;
}
module
.
exports
=
app
;
...
...
Please
register
or
login
to post a comment