This commit is contained in:
Skylar Grant 2024-09-22 15:27:05 -04:00
parent 656123926e
commit 52f8736d03
4 changed files with 45 additions and 13 deletions

View File

@ -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]
});

View File

@ -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();
},

View File

@ -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
// #############################################################

32
src/public/index.html Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webhook Tester</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
function triggerWebhook(url, body) {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch((error) => console.error('Error:', error));
}
</script>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="bg-white p-8 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Webhook Tester</h1>
<button onclick="triggerWebhook('https://whtest.vfsh.dev/hooks/topgg', {user: '481933290912350209', type: 'test', query: '', bot: '521624335119810561'})" class="bg-blue-500 text-white px-4 py-2 rounded mb-2">Test TOPGG Webhook</button>
<button onclick="triggerWebhook('https://whtest.vfsh.dev/hooks/uptime', {heartbeat: null, monitor: null, msg: 'HookShot Testing'})" class="bg-green-500 text-white px-4 py-2 rounded mb-2">Test Uptime Kuma Webhook</button>
<button onclick="triggerWebhook('https://whtest.vfsh.dev/hooks/testing', { type: 'test' })" class="bg-red-500 text-white px-4 py-2 rounded">Test Testing Webhook</button>
<button onclick="triggerWebhook('https://status.vfsh.dev/api/push/agA3tPLrWq?status=up&msg=OK&ping=', { type: 'test' })" class="bg-red-500 text-white px-4 py-2 rounded">Send Heartbeat to UK</button>
</div>
</body>
</html>