Showing
1 changed file
with
37 additions
and
11 deletions
... | @@ -13,8 +13,9 @@ const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ... | @@ -13,8 +13,9 @@ const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
13 | const TOKEN = 'EyomUcCS5ksQZGEvfMJX4JsOZ3C3qrdnU7dK11wHngy' | 13 | const TOKEN = 'EyomUcCS5ksQZGEvfMJX4JsOZ3C3qrdnU7dK11wHngy' |
14 | 14 | ||
15 | // 공공보건포털_API | 15 | // 공공보건포털_API |
16 | -const TARGET_URL2 = 'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'; | 16 | +const CORONA_URL = 'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'; |
17 | const SERVICE_KEY = 'DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D' | 17 | const SERVICE_KEY = 'DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D' |
18 | +var queryParams = '?' + encodeURIComponent('ServiceKey') + '=DMUPOq6b%2B%2F1gqfLEXQ6bnhgoTO73BfPprA6HVNcV%2F6vHMGG%2Bgiw%2BPDkPvX1eQ7b9uvl%2B42fxUPkU0W3Si907Lw%3D%3D'; | ||
18 | 19 | ||
19 | // express 미들웨어 정의 | 20 | // express 미들웨어 정의 |
20 | var app = express(); | 21 | var app = express(); |
... | @@ -47,7 +48,38 @@ app.post('/hook', function (request, response) { | ... | @@ -47,7 +48,38 @@ app.post('/hook', function (request, response) { |
47 | response.sendStatus(200); | 48 | response.sendStatus(200); |
48 | }); | 49 | }); |
49 | 50 | ||
50 | - | 51 | +function bot_reply(replyToken, message) { |
52 | + request.post( | ||
53 | + { | ||
54 | + url: CORONA_URL + queryParams, | ||
55 | + method: 'GET' | ||
56 | + },(error, response, body) => { | ||
57 | + if(!error && response.statusCode == 200) { | ||
58 | + console.log('Status', response.statusCode); | ||
59 | + console.log('Headers', JSON.stringify(response.headers)); | ||
60 | + var xmlToJson = convert.xml2json(body, {compact: false, spaces: 4}); | ||
61 | + console.log('Response received', xmlToJson); | ||
62 | + request.post( | ||
63 | + { | ||
64 | + url: TARGET_URL, | ||
65 | + headers: { | ||
66 | + 'Authorization': `Bearer ${TOKEN}` | ||
67 | + }, | ||
68 | + json: { | ||
69 | + "replyToken":replyToken, | ||
70 | + "messages":[ | ||
71 | + { | ||
72 | + "type":"text", | ||
73 | + "text":xmlToJson | ||
74 | + } | ||
75 | + ] | ||
76 | + } | ||
77 | + },(error, response, body) => { | ||
78 | + console.log(body) | ||
79 | + }); | ||
80 | + } | ||
81 | + }); | ||
82 | +} | ||
51 | 83 | ||
52 | 84 | ||
53 | 85 | ||
... | @@ -62,7 +94,8 @@ queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponen | ... | @@ -62,7 +94,8 @@ queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponen |
62 | 94 | ||
63 | 95 | ||
64 | // 공공보건포털에 요청 | 96 | // 공공보건포털에 요청 |
65 | -app.request({ | 97 | +/* |
98 | +request({ | ||
66 | url: url + queryParams, | 99 | url: url + queryParams, |
67 | method: 'GET' | 100 | method: 'GET' |
68 | }, function (error, response, body) { | 101 | }, function (error, response, body) { |
... | @@ -70,14 +103,7 @@ app.request({ | ... | @@ -70,14 +103,7 @@ app.request({ |
70 | console.log('Headers', JSON.stringify(response.headers)); | 103 | console.log('Headers', JSON.stringify(response.headers)); |
71 | console.log('Reponse received', body); | 104 | console.log('Reponse received', body); |
72 | }); | 105 | }); |
73 | - | 106 | +*/ |
74 | - | ||
75 | - | ||
76 | - | ||
77 | -function getResponeElement({ | ||
78 | - | ||
79 | -}); | ||
80 | - | ||
81 | 107 | ||
82 | // 오류처리 | 108 | // 오류처리 |
83 | try { | 109 | try { | ... | ... |
-
Please register or login to post a comment