Toggle navigation
Toggle navigation
This project
Loading...
Sign in
방승일
/
Stock_Alert_Chatbot
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
EC2 Default User
2022-06-08 15:36:06 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2b55ca97e9d5b7c9362ea69ab32eff365ec221cb
2b55ca97
1 parent
5ec10154
EDIT : Improve reply.js
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
8 deletions
reply.js
reply.js
View file @
2b55ca9
...
...
@@ -11,6 +11,9 @@ const sslport = 23023;
var
client_id
=
'YOUR_CLIENT_ID'
;
var
client_secret
=
'YOUR_CLIENT_SECRET'
;
var
newsOn
=
false
;
var
newsOff
=
true
;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
...
...
@@ -26,7 +29,51 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
true
)
{
if
(
message
.
text
==
'news on'
)
{
newsOn
=
true
;
newsOff
=
false
;
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"[news On] 키워드를 입력 하세요."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
else
if
(
message
.
text
==
'news off'
)
{
newsOn
=
false
;
newsOff
=
true
;
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"[news Off] 뉴스를 종료합니다."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
if
(
newsOn
&
message
.
text
!=
'help'
&
message
.
text
!=
'news on'
)
{
var
api_url
=
'https://openapi.naver.com/v1/search/news?query='
+
encodeURI
(
message
.
text
);
// json 결과
var
options
=
{
url
:
api_url
,
...
...
@@ -48,11 +95,15 @@ app.post('/hook', function (req, res) {
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
JSON
.
stringify
(
obj2
.
link
)
"text"
:
"<<<헤드라인>>>\n"
+
JSON
.
stringify
(
obj2
.
title
).
replace
(
/<
[^
>
]
*>
?
/g
,
''
)
},
{
"type"
:
"text"
,
"text"
:
"<<<주요문단>>>\n"
+
JSON
.
stringify
(
obj2
.
description
).
replace
(
/<
[^
>
]
*>
?
/g
,
''
)
},
{
"type"
:
"text"
,
"text"
:
JSON
.
stringify
(
obj2
.
description
).
replace
(
/<
[^
>
]
*>
?
/g
,
''
)
"text"
:
"뉴스 바로가기\n"
+
JSON
.
stringify
(
obj2
.
link
)
}
]
}
...
...
@@ -80,11 +131,13 @@ app.post('/hook', function (req, res) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"반갑습니다. 주식 알리미 입니다."
},
{
"type"
:
"text"
,
"text"
:
"주식 관련 뉴스를 원하시면 \'뉴스\' 입력 후 원하는 종목을 검색하세요."
"text"
:
"*****************\
\n반갑습니다. 주식 news 알리미 입니다.\
\n1. 뉴스 검색 기능 활성화\
\n\'news on\' 입력\
\n2. 뉴스 검색 기능 비활성화\
\n\'news off\' 입력\
\n*****************"
}
]
}
...
...
Please
register
or
login
to post a comment