1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2025-07-17 04:15:15 +02:00

Add Discord notification (#35)

add discord notification
This commit is contained in:
Anthony Graignic
2021-02-23 14:32:08 +02:00
committed by GitHub
parent ee586c9e64
commit ccec34ff5d
4 changed files with 43 additions and 1 deletions

View File

@ -90,6 +90,30 @@ export async function notifyTelegram(monitor, operational) {
})
}
// Visualize your payload using https://leovoel.github.io/embed-visualizer/
export async function notifyDiscord(monitor, operational) {
const payload = {
username: `${config.settings.title}`,
avatar_url: `${config.settings.url}/${config.settings.logo}`,
embeds: [
{
title: `${monitor.name} is ${getOperationalLabel(operational)} ${
operational ? ':white_check_mark:' : ':x:'
}`,
description: `\`${monitor.method ? monitor.method : 'GET'} ${
monitor.url
}\` - :eyes: [Status Page](${config.settings.url})`,
color: operational ? 3581519 : 13632027,
},
],
}
return fetch(SECRET_DISCORD_WEBHOOK_URL, {
body: JSON.stringify(payload),
method: 'POST',
headers: { 'Content-Type': 'application/json' },
})
}
export function useKeyPress(targetKey) {
const [keyPressed, setKeyPressed] = useState(false)