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
조현아
2019-06-02 01:07:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd76b9e2ad9d06fd88fe304cbf69bbbe35916294
dd76b9e2
1 parent
822be3d0
add menu
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
5 deletions
app.js
menu.js
package-lock.json
package.json
app.js
View file @
dd76b9e
var
express
=
require
(
'express'
);
var
app
=
express
();
const
line
=
require
(
'@line/bot-sdk'
);
const
config
=
require
(
'./config'
);
const
config
=
require
(
'./config
.js
'
);
//papago api
...
...
@@ -23,7 +23,11 @@ const client = new line.Client(config.line_config);
// register a webhook handler with middleware
// about the middleware, please refer to doc
app
.
post
(
'/webhook'
,
line
.
middleware
(
config
),
(
req
,
res
)
=>
{
const
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/webhook'
,
line
.
middleware
(
config
.
line_config
),
(
req
,
res
)
=>
{
Promise
.
all
(
req
.
body
.
events
.
map
(
handleEvent
))
.
then
((
result
)
=>
res
.
json
(
result
))
...
...
@@ -31,15 +35,23 @@ app.post('/webhook', line.middleware(config), (req, res) => {
console
.
error
(
err
);
res
.
status
(
200
).
end
();
});
console
.
log
(
'[result]'
,
req
.
json
(
result
));
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source]'
,
req
.
body
.
events
[
0
].
source
);
console
.
log
(
'[request message]'
,
req
.
body
.
events
[
0
].
message
);
});
// event handler
function
handleEvent
(
event
)
{
console
.
log
(
"event.message.text"
);
if
(
event
.
type
!==
'message'
||
event
.
message
.
type
!==
'text'
)
{
console
.
log
(
"2"
);
// ignore non-text-message event
return
Promise
.
resolve
(
null
);
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
console
.
log
(
"3"
);
//언어 감지 option
var
detect_options
=
{
url
:
languagedetect_api_url
,
...
...
@@ -49,6 +61,7 @@ function handleEvent(event) {
//papago 언어 감지
request
.
post
(
detect_options
,
function
(
error
,
response
,
body
){
console
.
log
(
"4"
);
console
.
log
(
response
.
statusCode
);
if
(
!
error
&&
response
.
statusCode
==
200
){
var
detect_body
=
JSON
.
parse
(
response
.
body
);
...
...
@@ -62,6 +75,7 @@ function handleEvent(event) {
//번역은 한국어->영어 / 영어->한국어만 지원
if
(
detect_body
.
langCode
==
'ko'
||
detect_body
.
langCode
==
'en'
){
console
.
log
(
"5"
);
source
=
detect_body
.
langCode
==
'ko'
?
'ko'
:
'en'
;
target
=
source
==
'ko'
?
'en'
:
'ko'
;
//papago 번역 option
...
...
@@ -74,7 +88,7 @@ function handleEvent(event) {
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
){
// Translate API Sucess
// Translate API Suc
c
ess
if
(
!
error
&&
response
.
statusCode
==
200
){
// JSON
var
objBody
=
JSON
.
parse
(
response
.
body
);
...
...
menu.js
0 → 100644
View file @
dd76b9e
curl
-
v
-
X
POST
https
:
//api.line.me/v2/bot/richmenu \
-
H
'Authorization: Bearer FemJMku1wbyrrbrvVcrppKimYhKbtsJKNZ5F4DgxtRKvZNYqY8lLamQLau8IlucsNKMgimU35uD+HaqVKHtrZ1L9IaPNBMdIBo5YSgcDwAf9lVMvieFK1dwpddi98XCdI2ma7kEIy5h3LzmEF3CLOQdB04t89/1O/w1cDnyilFU='
\
-
H
'Content-Type:application/json'
\
-
d
\
'{
"size": {
"width": 800,
"height": 540
},
"selected": false,
"name": "번역 옵션",
"chatBarText": "번역 옵션",
"areas": [{
"bounds": {
"x": 0,
"y": 270,
"width": 400,
"height": 270
},
"action": {
"type": "message",
"text": "문법을 검사합니다."
}
},
{
"bounds": {
"x": 400,
"y": 270,
"width": 400,
"height": 270
},
"action": {
"type": "message",
"text": "이미지 내 문장을 번역합니다."
}
},
{
"bounds": {
"x": 0,
"y": 540,
"width": 400,
"height": 270
},
"action": {
"type": "message",
"quickReply": {
"items": [{
"type": "action",
"action": {
"type": "message",
"label": "영어",
"text": "영어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "일본어",
"text": "일본어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "중국어",
"text": "중국어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "스페인어",
"text": "스페인어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "독일어",
"text": "독일어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "프랑스어",
"text": "프랑스어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "러시아어",
"text": "러시아어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "태국어",
"text": "태국어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "인도네시아어",
"text": "인도네시아어"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "베트남어",
"text": "베트남어"
}
}
]
}
}
},
{
"bounds": {
"x": 400,
"y": 540,
"width": 400,
"height": 270
},
"action": {
"type": "message",
"text": "음성 듣기를 수행합니다."
}
}
]
}'
\ No newline at end of file
package-lock.json
View file @
dd76b9e
This diff is collapsed. Click to expand it.
package.json
View file @
dd76b9e
...
...
@@ -5,12 +5,14 @@
"main"
:
"app.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"start"
:
"node
server
.js"
"start"
:
"node
app
.js"
},
"author"
:
"강수인"
,
"license"
:
"MIT"
,
"dependencies"
:
{
"@line/bot-sdk"
:
"^6.4.0"
,
"express"
:
"^4.16.4"
"babel"
:
"^6.23.0"
,
"express"
:
"^4.17.1"
,
"request"
:
"^2.88.0"
}
}
...
...
Please
register
or
login
to post a comment