odin/libs/dadJokes.js
2022-11-27 20:40:30 +01:00

23 lines
No EOL
668 B
JavaScript

const request = require('request');
function getJoke(ctx, bot) {
const options = {
method: 'GET',
url: 'https://dad-jokes.p.rapidapi.com/random/joke',
headers: {
'X-RapidAPI-Key': process.env.DADJOKES,
'X-RapidAPI-Host': 'dad-jokes.p.rapidapi.com',
useQueryString: true
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
res = JSON.parse(body)
bot.telegram.sendMessage(ctx.chat.id, res.body[0].setup, {});
bot.telegram.sendMessage(ctx.chat.id, res.body[0].punchline, {});
});
}
module.exports = { getJoke };