Showing
1 changed file
with
21 additions
and
8 deletions
... | @@ -9,11 +9,13 @@ const domain = "2020105659.osschatbot.cf" | ... | @@ -9,11 +9,13 @@ const domain = "2020105659.osschatbot.cf" |
9 | const sslport = 23023; | 9 | const sslport = 23023; |
10 | 10 | ||
11 | //Open API | 11 | //Open API |
12 | -const STDICT_URL = 'https://stdict.korean.go.kr/api/search.do?' | 12 | +const STDICT_URL = 'https://stdict.korean.go.kr/api/search.do' |
13 | const STDICT_KEY = '14AA284251F616FF2151DBE4CD7B3D4C' | 13 | const STDICT_KEY = '14AA284251F616FF2151DBE4CD7B3D4C' |
14 | 14 | ||
15 | //Webhook | 15 | //Webhook |
16 | const bodyParser = require('body-parser'); | 16 | const bodyParser = require('body-parser'); |
17 | +const { json } = require('body-parser'); | ||
18 | +const { start } = require('repl'); | ||
17 | var app = express(); | 19 | var app = express(); |
18 | app.use(bodyParser.json()); | 20 | app.use(bodyParser.json()); |
19 | app.post('/hook', function (req, res) { | 21 | app.post('/hook', function (req, res) { |
... | @@ -35,21 +37,28 @@ app.post('/hook', function (req, res) { | ... | @@ -35,21 +37,28 @@ app.post('/hook', function (req, res) { |
35 | }); | 37 | }); |
36 | 38 | ||
37 | function wordchain(replyToken, message) { | 39 | function wordchain(replyToken, message) { |
40 | + | ||
38 | let letter = message.slice(-1); | 41 | let letter = message.slice(-1); |
39 | 42 | ||
40 | request.post( | 43 | request.post( |
41 | { | 44 | { |
42 | url: STDICT_URL, | 45 | url: STDICT_URL, |
43 | headers: { | 46 | headers: { |
44 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | 47 | + 'Referer': 'https://stdict.korean.go.kr/api/search.do', |
45 | - 'Stdict-Key': `${STDICT_KEY}` | 48 | + 'Content-Type': 'application/x-www-form-urlencoded' |
46 | }, | 49 | }, |
47 | - body: 'https://stdict.korean.go.kr/api/search.do?' + `key=${STDICT_KEY}` + `q=${letter}` + 'req_type=json' + 'advanced=y' + 'method=start', | 50 | + body: `key=14AA284251F616FF2151DBE4CD7B3D4C&` + `q=${letter}&` + 'req_type=json&' + 'advanced=y&' + 'method=start&' + 'letter_s=2' |
48 | - json:true | 51 | + |
49 | },(error, response, body) => { | 52 | },(error, response, body) => { |
50 | if(!error && response.statusCode == 200) { | 53 | if(!error && response.statusCode == 200) { |
51 | - console.log(body.message); | 54 | + console.log(body); |
52 | - var nextword = body.message.word.searchedWord; | 55 | + const parsedData = JSON.parse(body); |
56 | + var nextword = parsedData.channel.item[0].word; | ||
57 | + var word_definition = parsedData.channel.item[0].sense.definition; | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
53 | request.post( | 62 | request.post( |
54 | { | 63 | { |
55 | url: TARGET_URL, | 64 | url: TARGET_URL, |
... | @@ -62,11 +71,15 @@ function wordchain(replyToken, message) { | ... | @@ -62,11 +71,15 @@ function wordchain(replyToken, message) { |
62 | { | 71 | { |
63 | "type":"text", | 72 | "type":"text", |
64 | "text":nextword | 73 | "text":nextword |
74 | + }, | ||
75 | + { | ||
76 | + "type":"text", | ||
77 | + "text":': ' + word_definition | ||
65 | } | 78 | } |
66 | ] | 79 | ] |
67 | } | 80 | } |
68 | },(error, response, body) => { | 81 | },(error, response, body) => { |
69 | - console.log(body) | 82 | + console.log(body); |
70 | }); | 83 | }); |
71 | } | 84 | } |
72 | }); | 85 | }); | ... | ... |
-
Please register or login to post a comment