곽원석

Update modules

Showing 1 changed file with 38 additions and 12 deletions
......@@ -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 {
......