Toggle navigation
Toggle navigation
This project
Loading...
Sign in
전세계
/
FakerQuiz
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
전세계
2020-06-18 12:52:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f8c3f26300d069afad8ad222378928352a3902b8
f8c3f263
1 parent
54005315
테스트: line webhook 테스트
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
4 deletions
app.js
app.js
View file @
f8c3f26
...
...
@@ -7,6 +7,15 @@ const axios = require('axios');
const
cheerio
=
require
(
'cheerio'
);
const
url
=
'http://lol.inven.co.kr/dataninfo/proteam/progamer.php?code=135'
;
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
;
const
TOKEN
=
'ihoYpWsdObaqmCnQ7nqwBfSGiLV4v3OZSqccIK9osz9y9pOMiKgEpmJ8fHiiBT0rF5wZoa2bRGTQjZ7al4yseviaYPsROO4nyiygZi8lvW2xcD6yakxXZ91eNmzz8e6fQ32IPZ577Iagx/kEQ/UMgAdB04t89/1O/w1cDnyilFU='
;
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"www.sekechatbot.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
const
version
=
'0.1'
;
const
dataFileName
=
'data.json'
;
...
...
@@ -204,9 +213,56 @@ async function getData() {
});
}
app
.
get
(
'/'
,
(
req
,
res
)
=>
{
res
.
send
(
'Express Test'
);
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
sendMessage
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
res
.
sendStatus
(
200
);
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`app listening at http://localhost:
${
port
}
`
));
\ No newline at end of file
function
sendMessage
(
replyToken
,
message
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"test"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
}
);
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment