Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
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-12-07 13:15:21 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
70624754645228ec880ba683b027d440c0a5e40e
70624754
1 parent
c2ef91a0
Final Commit
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
67 deletions
routes/message.js
routes/message.js
View file @
7062475
...
...
@@ -18,7 +18,7 @@ app.post('/', function(req, res) {
};
if
(
_obj
.
content
.
charAt
(
0
)
==
'/'
){
if
(
_obj
.
content
==
'/설정'
){
/*
if(_obj.content == '/설정'){
res.set('content-type', 'application/json');
res.json({
"message": {
...
...
@@ -36,72 +36,24 @@ app.post('/', function(req, res) {
]
}
});
}
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*/
if
(
_obj
.
content
==
'/시작'
){
res
.
json
({
"message"
:
{
"text"
:
"영어를 한글로 번역해드리겠습니다. 자 시작!"
// "text": "언어를 설정하고 싶으면 /설정 이라고 타이핑 해주세요"
},
"keyboard"
:
{
"type"
:
"text"
}
});
}
else
{
res
.
set
(
'content-type'
,
'application/json'
);
res
.
json
({
"message"
:
{
"text"
:
"/기호가 들어간 명령어는 사용할 수 없습니다."
}
});
}
}
else
{
// Naver Papago Translate
var
options
=
{
...
...
@@ -167,3 +119,4 @@ function choiceLanguage(str) {
}
module
.
exports
=
app
;
...
...
Please
register
or
login
to post a comment