Toggle navigation
Toggle navigation
This project
Loading...
Sign in
곽원석
/
OSS-Project
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
곽원석
2020-12-08 14:20:39 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9889129caef562a7aa0cbf08451153102d659e73
9889129c
1 parent
39af0e82
Update modules
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
12 deletions
app.js
app.js
View file @
9889129
...
...
@@ -13,8 +13,9 @@ const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'EyomUcCS5ksQZGEvfMJX4JsOZ3C3qrdnU7dK11wHngy'
// 공공보건포털_API
const
TARGET_URL2
=
'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'
;
const
CORONA_URL
=
'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'
;
const
SERVICE_KEY
=
'DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D'
var
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'=DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D'
;
// express 미들웨어 정의
var
app
=
express
();
...
...
@@ -40,14 +41,45 @@ app.post('/hook', function (request, response) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
response
.
sendStatus
(
200
);
});
function
bot_reply
(
replyToken
,
message
)
{
request
.
post
(
{
url
:
CORONA_URL
+
queryParams
,
method
:
'GET'
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
var
xmlToJson
=
convert
.
xml2json
(
body
,
{
compact
:
false
,
spaces
:
4
});
console
.
log
(
'Response received'
,
xmlToJson
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
xmlToJson
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
...
...
@@ -62,7 +94,8 @@ queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponen
// 공공보건포털에 요청
app
.
request
({
/*
request({
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
...
...
@@ -70,14 +103,7 @@ app.request({
console.log('Headers', JSON.stringify(response.headers));
console.log('Reponse received', body);
});
function
getResponeElement
({
});
*/
// 오류처리
try
{
...
...
Please
register
or
login
to post a comment