EC2 Default User

Add word definition

Showing 1 changed file with 21 additions and 8 deletions
......@@ -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);
});
}
});
......