mirror of
https://github.com/tormachris/cf-workers-status-page.git
synced 2025-07-05 11:32:48 +02:00
@ -6,6 +6,7 @@ import {
|
||||
getCheckLocation,
|
||||
getKVMonitors,
|
||||
setKVMonitors,
|
||||
notifyDiscord,
|
||||
} from './helpers'
|
||||
|
||||
function getDate() {
|
||||
@ -88,6 +89,15 @@ export async function processCronTrigger(event) {
|
||||
event.waitUntil(notifyTelegram(monitor, monitorOperational))
|
||||
}
|
||||
|
||||
// Send Discord message on monitor change
|
||||
if (
|
||||
monitorStatusChanged &&
|
||||
typeof SECRET_DISCORD_WEBHOOK_URL !== 'undefined' &&
|
||||
SECRET_DISCORD_WEBHOOK_URL !== 'default-gh-action-secret'
|
||||
) {
|
||||
event.waitUntil(notifyDiscord(monitor, monitorOperational))
|
||||
}
|
||||
|
||||
// make sure checkDay exists in checks in cases when needed
|
||||
if (
|
||||
(config.settings.collectResponseTimes || !monitorOperational) &&
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user