Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정윤지
/
Word_Chain_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
2021-12-08 14:35:05 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1026934bb8509d3fb346f6508df86d4fc9ab7ba3
1026934b
1 parent
d0065907
Add word definition
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
app.js
app.js
View file @
1026934
...
...
@@ -9,11 +9,13 @@ const domain = "2020105659.osschatbot.cf"
const
sslport
=
23023
;
//Open API
const
STDICT_URL
=
'https://stdict.korean.go.kr/api/search.do
?
'
const
STDICT_URL
=
'https://stdict.korean.go.kr/api/search.do'
const
STDICT_KEY
=
'14AA284251F616FF2151DBE4CD7B3D4C'
//Webhook
const
bodyParser
=
require
(
'body-parser'
);
const
{
json
}
=
require
(
'body-parser'
);
const
{
start
}
=
require
(
'repl'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -35,21 +37,28 @@ app.post('/hook', function (req, res) {
});
function
wordchain
(
replyToken
,
message
)
{
let
letter
=
message
.
slice
(
-
1
);
request
.
post
(
{
url
:
STDICT_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8
'
,
'Stdict-Key'
:
`
${
STDICT_KEY
}
`
'Referer'
:
'https://stdict.korean.go.kr/api/search.do
'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
body
:
'https://stdict.korean.go.kr/api/search.do?'
+
`key=
${
STDICT_KEY
}
`
+
`q=
${
letter
}
`
+
'req_type=json'
+
'advanced=y'
+
'method=start'
,
json
:
true
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
letter
}
&`
+
'req_type=json&'
+
'advanced=y&'
+
'method=start&'
+
'letter_s=2'
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
body
.
message
);
var
nextword
=
body
.
message
.
word
.
searchedWord
;
console
.
log
(
body
);
const
parsedData
=
JSON
.
parse
(
body
);
var
nextword
=
parsedData
.
channel
.
item
[
0
].
word
;
var
word_definition
=
parsedData
.
channel
.
item
[
0
].
sense
.
definition
;
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -62,11 +71,15 @@ function wordchain(replyToken, message) {
{
"type"
:
"text"
,
"text"
:
nextword
},
{
"type"
:
"text"
,
"text"
:
': '
+
word_definition
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
console
.
log
(
body
)
;
});
}
});
...
...
Please
register
or
login
to post a comment