Showing
1 changed file
with
40 additions
and
4 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | +const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | ||
4 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | 5 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' |
5 | const TOKEN = '' | 6 | const TOKEN = '' |
6 | const fs = require('fs'); | 7 | const fs = require('fs'); |
... | @@ -11,7 +12,14 @@ const sslport = 23023; | ... | @@ -11,7 +12,14 @@ const sslport = 23023; |
11 | 12 | ||
12 | const bodyParser = require('body-parser'); | 13 | const bodyParser = require('body-parser'); |
13 | var app = express(); | 14 | var app = express(); |
14 | - | 15 | + |
16 | +// broadcast route | ||
17 | +var period_broadcast = 50000; | ||
18 | +var count_broadcast = 0; | ||
19 | +setInterval(function(){ | ||
20 | + broadcast(); | ||
21 | +}, period_broadcast); | ||
22 | + | ||
15 | app.use(bodyParser.json()); | 23 | app.use(bodyParser.json()); |
16 | app.post('/hook', function (req, res) { | 24 | app.post('/hook', function (req, res) { |
17 | 25 | ||
... | @@ -24,13 +32,16 @@ app.post('/hook', function (req, res) { | ... | @@ -24,13 +32,16 @@ app.post('/hook', function (req, res) { |
24 | console.log('[request]', req.body); | 32 | console.log('[request]', req.body); |
25 | console.log('[request source] ', eventObj.source); | 33 | console.log('[request source] ', eventObj.source); |
26 | console.log('[request message]', eventObj.message); | 34 | console.log('[request message]', eventObj.message); |
35 | + | ||
27 | 36 | ||
28 | var isNationWide = message.text; | 37 | var isNationWide = message.text; |
29 | var sub_nationwide = "국내"; | 38 | var sub_nationwide = "국내"; |
30 | if(isNationWide.indexOf(sub_nationwide) !== -1){ | 39 | if(isNationWide.indexOf(sub_nationwide) !== -1){ |
31 | replyNationWide(eventObj); | 40 | replyNationWide(eventObj); |
32 | } | 41 | } |
33 | - else if(message.text == "야" || message.text == "도움말"){ | 42 | + |
43 | + var sub_hello = "어떻게" | ||
44 | + if(message.text == "야" || message.text == "도움말" || message.text.indexOf(sub_hello) !== -1){ | ||
34 | hello(eventObj) | 45 | hello(eventObj) |
35 | } | 46 | } |
36 | 47 | ||
... | @@ -97,7 +108,7 @@ function hello(eventObj) { | ... | @@ -97,7 +108,7 @@ function hello(eventObj) { |
97 | "messages":[ | 108 | "messages":[ |
98 | { | 109 | { |
99 | "type":"text", | 110 | "type":"text", |
100 | - "text":"안녕하십니까. 코로나 도우미 입니다." | 111 | + "text":"안녕하십니까. 코로나 알리미 입니다." |
101 | }, | 112 | }, |
102 | { | 113 | { |
103 | "type":"text", | 114 | "type":"text", |
... | @@ -117,7 +128,8 @@ function hello(eventObj) { | ... | @@ -117,7 +128,8 @@ function hello(eventObj) { |
117 | } | 128 | } |
118 | 129 | ||
119 | // Broadcast | 130 | // Broadcast |
120 | -function broadcast(eventObj){ | 131 | +function broadcast(){ |
132 | + | ||
121 | request.post( | 133 | request.post( |
122 | { | 134 | { |
123 | url: BROAD_TARGET_URL, | 135 | url: BROAD_TARGET_URL, |
... | @@ -141,6 +153,30 @@ function broadcast(eventObj){ | ... | @@ -141,6 +153,30 @@ function broadcast(eventObj){ |
141 | }); | 153 | }); |
142 | } | 154 | } |
143 | 155 | ||
156 | +// Multicast User | ||
157 | +// request.post( | ||
158 | +// { | ||
159 | +// url: MULTI_TARGET_URL, | ||
160 | +// headers: { | ||
161 | +// 'Authorization': `Bearer ${TOKEN}` | ||
162 | +// }, | ||
163 | +// json: { | ||
164 | +// "to": [`${USER_ID}`], | ||
165 | +// "messages":[ | ||
166 | +// { | ||
167 | +// "type":"text", | ||
168 | +// "text":"Hello, user" | ||
169 | +// }, | ||
170 | +// { | ||
171 | +// "type":"text", | ||
172 | +// "text":"May I help you?" | ||
173 | +// } | ||
174 | +// ] | ||
175 | +// } | ||
176 | +// },(error, response, body) => { | ||
177 | +// console.log(body) | ||
178 | +// }); | ||
179 | + | ||
144 | try { | 180 | try { |
145 | const option = { | 181 | const option = { |
146 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 182 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment