Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장수창
/
COVID19_Information_Chatbot
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-19 16:03:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d25b714502cbb08cac99bfac2648626c9066f6fe
d25b7145
1 parent
f97d9bdb
broadcast to user
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
4 deletions
nodejs/app.js
nodejs/app.js
View file @
d25b714
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
MULTI_TARGET_URL
=
'https://api.line.me/v2/bot/message/multicast'
const
BROAD_TARGET_URL
=
'https://api.line.me/v2/bot/message/broadcast'
const
TOKEN
=
''
const
fs
=
require
(
'fs'
);
...
...
@@ -11,7 +12,14 @@ const sslport = 23023;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
// broadcast route
var
period_broadcast
=
50000
;
var
count_broadcast
=
0
;
setInterval
(
function
(){
broadcast
();
},
period_broadcast
);
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -24,13 +32,16 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
var
isNationWide
=
message
.
text
;
var
sub_nationwide
=
"국내"
;
if
(
isNationWide
.
indexOf
(
sub_nationwide
)
!==
-
1
){
replyNationWide
(
eventObj
);
}
else
if
(
message
.
text
==
"야"
||
message
.
text
==
"도움말"
){
var
sub_hello
=
"어떻게"
if
(
message
.
text
==
"야"
||
message
.
text
==
"도움말"
||
message
.
text
.
indexOf
(
sub_hello
)
!==
-
1
){
hello
(
eventObj
)
}
...
...
@@ -97,7 +108,7 @@ function hello(eventObj) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"안녕하십니까. 코로나
도우
미 입니다."
"text"
:
"안녕하십니까. 코로나
알리
미 입니다."
},
{
"type"
:
"text"
,
...
...
@@ -117,7 +128,8 @@ function hello(eventObj) {
}
// Broadcast
function
broadcast
(
eventObj
){
function
broadcast
(){
request
.
post
(
{
url
:
BROAD_TARGET_URL
,
...
...
@@ -141,6 +153,30 @@ function broadcast(eventObj){
});
}
// Multicast User
// request.post(
// {
// url: MULTI_TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "to": [`${USER_ID}`],
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
...
...
Please
register
or
login
to post a comment