Toggle navigation
Toggle navigation
This project
Loading...
Sign in
kykint
/
TELEGRAMBOT
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
강수인
2018-12-07 00:48:00 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
006c9e9e60789cf41a6c5a28cf8f0453a772b090
006c9e9e
1 parent
475062e9
라인에서 필요 없는 js 파일 삭제
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
174 deletions
routes/line.js
routes/message.js
routes/line.js
deleted
100644 → 0
View file @
475062e
const
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/webhook'
,
function
(
request
,
response
)
{
var
eventObj
=
request
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
request
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
message
.
type
==
"text"
){
reply
.
send
(
config
.
CHANNEL_ACCESS_TOKEN
,
eventObj
.
replyToken
,
'welcome sooinzzang.com'
);
}
/*
if(message.type = "text" && message.text.indexOf("@momo") != -1){
reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionBasic.getBasicExpress());
}
else if(message.type = "text" && /^@.+/g.test(message.text)){
var cmd = message.text.split('@')[1];
console.log('[command]', cmd);
if(typeof cmd !== "undefined" && cmd != ""){
if(cmd == "h" || cmd == "help"){
reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionHelp.getHelpExpress());
}
else if(/^r\[.+\]/g.test(cmd)){
reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionEnjoy.getRandomExpress(cmd));
}
else if(cmd == "food" || cmd == "밥집"){
reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionEnjoy.getFoodExpress());
}
else if(cmd == "contact" || cmd == "ct"){
reply.send(config.CHANNEL_ACCESS_TOKEN, eventObj.replyToken, actionHelp.getContactExpress());
}
}
}
*/
response
.
sendStatus
(
200
);
});
routes/message.js
deleted
100644 → 0
View file @
475062e
var
express
=
require
(
'express'
);
var
request
=
require
(
'request'
);
var
app
=
express
.
Router
();
// Naver Auth Key
var
client_id
=
'86rKmat0DijccSxKa01P'
;
var
client_secret
=
'rMapNjB8DP'
;
// Naver API URL
var
api_url
=
'https://openapi.naver.com/v1/papago/n2mt'
;
// Kakao Message API
app
.
post
(
'/'
,
function
(
req
,
res
)
{
const
_obj
=
{
user_key
:
req
.
body
.
user_key
,
type
:
req
.
body
.
type
,
content
:
req
.
body
.
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"
:
"영어를 한글로 번역해드리겠습니다. 자 시작!"
// "text": "언어를 설정하고 싶으면 /설정 이라고 타이핑 해주세요"
},
"keyboard"
:
{
"type"
:
"text"
}
});
}
else
{
res
.
set
(
'content-type'
,
'application/json'
);
res
.
json
({
"message"
:
{
"text"
:
"/기호가 들어간 명령어는 사용할 수 없습니다."
}
});
}
}
else
{
// Naver Papago Translate
var
options
=
{
url
:
api_url
,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form
:
{
'source'
:
'ko'
,
'target'
:
'en'
,
'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
));
}
});
}
});
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