From 52f8736d0341ebe0451a272ab9ecbb63922fff03 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 22 Sep 2024 15:27:05 -0400 Subject: [PATCH] MVP --- src/DjsHandlers.js | 8 +++----- src/Handlers.js | 6 +++--- src/index.js | 12 +++++++----- src/public/index.html | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 src/public/index.html diff --git a/src/DjsHandlers.js b/src/DjsHandlers.js index 503ceb4..ff08c0a 100644 --- a/src/DjsHandlers.js +++ b/src/DjsHandlers.js @@ -42,7 +42,6 @@ module.exports = { }); }, topggVote(body) { - console.log(body); // Create a new WebhookClient const webhookClient = new WebhookClient({ id: whInfo.topgg.id, token: whInfo.topgg.token }); @@ -59,19 +58,18 @@ module.exports = { }); }, uptimeKumaAlert(body) { - console.log(body); // Create a new WebhookClient const webhookClient = new WebhookClient({ id: whInfo.uptimeKuma.id, token: whInfo.uptimeKuma.token }); // Create a new EmbedBuilder + const state = body.heartbeat.status === 1 ? 'Up' : 'Down'; const embed = new EmbedBuilder() - .setTitle('Uptime Kuma Alert') - .setDescription(`Service: ${body.service}`) + .setTitle(`${body.monitor.name} Uptime Alert`) + .setDescription(`State: ${state}\n\n${body.msg}`) .setTimestamp(); // Send the Embed webhookClient.send({ - content: 'Uptime Kuma has detected an issue with a service', username: config.discord.uptimeKuma.username, embeds: [embed] }); diff --git a/src/Handlers.js b/src/Handlers.js index 6b33eb9..e905f37 100644 --- a/src/Handlers.js +++ b/src/Handlers.js @@ -1,9 +1,9 @@ const djs = require('./DjsHandlers.js'); module.exports = { - generic(req, res) { - // Handle generic webhook payload here - console.log('Received generic webhook payload:', req.body); + testing(req, res) { + // Handle test webhook payload here + console.log('Received test webhook payload:', req.body); res.sendStatus(200); djs.testing(); }, diff --git a/src/index.js b/src/index.js index 8566ff1..85f4a49 100644 --- a/src/index.js +++ b/src/index.js @@ -10,8 +10,10 @@ const handlers = require('./Handlers.js'); // ############################################################# const port = 3000; const locations = { + "testing": "/hooks/testing", "topgg": "/hooks/vote", - "uptimeKuma": "/hooks/uptime" + "uptimeKuma": "/hooks/uptime", + "cp": "/cp" }; // ############################################################# @@ -19,15 +21,14 @@ const locations = { // ############################################################# dotenv.config(); const app = express(); - app.use(express.json()); // ############################################################# // Webhook Listeners // ############################################################# -// Genertic Webhook -app.post('/webhook', handlers.generic); +// Testing Webhook +app.post(locations.testing, handlers.testing); // Top.gg Votes app.post(locations.topgg, handlers.topgg); @@ -36,7 +37,7 @@ app.post(locations.topgg, handlers.topgg); app.post(locations.uptimeKuma, handlers.uptimeKuma); // Genertic Webhook -app.get('/webhook', handlers.generic); +app.get('/webhook', handlers.testing); // Top.gg Votes app.get(locations.topgg, handlers.topgg); @@ -44,6 +45,7 @@ app.get(locations.topgg, handlers.topgg); // Uptime Kuma Alerts app.get(locations.uptimeKuma, handlers.uptimeKuma); + // ############################################################# // Function Calls / Start Listening // ############################################################# diff --git a/src/public/index.html b/src/public/index.html new file mode 100644 index 0000000..43bd27f --- /dev/null +++ b/src/public/index.html @@ -0,0 +1,32 @@ + + + + + + Webhook Tester + + + + +
+

Webhook Tester

+ + + + +
+ + \ No newline at end of file