mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-21 11:28:47 +00:00
feat(notifications): add support for custom notifications in build error alerts
This commit is contained in:
@@ -5,6 +5,7 @@ import { renderAsync } from "@react-email/components";
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import {
|
import {
|
||||||
|
sendCustomNotification,
|
||||||
sendDiscordNotification,
|
sendDiscordNotification,
|
||||||
sendEmailNotification,
|
sendEmailNotification,
|
||||||
sendGotifyNotification,
|
sendGotifyNotification,
|
||||||
@@ -35,7 +36,7 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
const notificationList = await db.query.notifications.findMany({
|
const notificationList = await db.query.notifications.findMany({
|
||||||
where: and(
|
where: and(
|
||||||
eq(notifications.appBuildError, true),
|
eq(notifications.appBuildError, true),
|
||||||
eq(notifications.organizationId, organizationId),
|
eq(notifications.organizationId, organizationId)
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
email: true,
|
email: true,
|
||||||
@@ -44,11 +45,13 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
slack: true,
|
slack: true,
|
||||||
gotify: true,
|
gotify: true,
|
||||||
ntfy: true,
|
ntfy: true,
|
||||||
|
custom: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const notification of notificationList) {
|
for (const notification of notificationList) {
|
||||||
const { email, discord, telegram, slack, gotify, ntfy } = notification;
|
const { email, discord, telegram, slack, gotify, ntfy, custom } =
|
||||||
|
notification;
|
||||||
if (email) {
|
if (email) {
|
||||||
const template = await renderAsync(
|
const template = await renderAsync(
|
||||||
BuildFailedEmail({
|
BuildFailedEmail({
|
||||||
@@ -58,7 +61,7 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
errorMessage: errorMessage,
|
errorMessage: errorMessage,
|
||||||
buildLink,
|
buildLink,
|
||||||
date: date.toLocaleString(),
|
date: date.toLocaleString(),
|
||||||
}),
|
})
|
||||||
).catch();
|
).catch();
|
||||||
await sendEmailNotification(email, "Build failed for dokploy", template);
|
await sendEmailNotification(email, "Build failed for dokploy", template);
|
||||||
}
|
}
|
||||||
@@ -130,7 +133,7 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
`${decorate("❔", `Type: ${applicationType}`)}` +
|
`${decorate("❔", `Type: ${applicationType}`)}` +
|
||||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||||
`${decorate("⚠️", `Error:\n${errorMessage}`)}` +
|
`${decorate("⚠️", `Error:\n${errorMessage}`)}` +
|
||||||
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
|
`${decorate("🔗", `Build details:\n${buildLink}`)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +147,7 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
`⚙️Application: ${applicationName}\n` +
|
`⚙️Application: ${applicationName}\n` +
|
||||||
`❔Type: ${applicationType}\n` +
|
`❔Type: ${applicationType}\n` +
|
||||||
`🕒Date: ${date.toLocaleString()}\n` +
|
`🕒Date: ${date.toLocaleString()}\n` +
|
||||||
`⚠️Error:\n${errorMessage}`,
|
`⚠️Error:\n${errorMessage}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +163,14 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
|
|
||||||
await sendTelegramNotification(
|
await sendTelegramNotification(
|
||||||
telegram,
|
telegram,
|
||||||
`<b>⚠️ Build Failed</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`,
|
`<b>⚠️ Build Failed</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(
|
||||||
inlineButton,
|
date,
|
||||||
|
"PP"
|
||||||
|
)}\n<b>Time:</b> ${format(
|
||||||
|
date,
|
||||||
|
"pp"
|
||||||
|
)}\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`,
|
||||||
|
inlineButton
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,5 +220,21 @@ export const sendBuildErrorNotifications = async ({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (custom) {
|
||||||
|
await sendCustomNotification(custom, {
|
||||||
|
title: "Build Error",
|
||||||
|
message: "Build failed with errors",
|
||||||
|
projectName,
|
||||||
|
applicationName,
|
||||||
|
applicationType,
|
||||||
|
errorMessage,
|
||||||
|
buildLink,
|
||||||
|
timestamp: date.toISOString(),
|
||||||
|
date: date.toLocaleString(),
|
||||||
|
status: "error",
|
||||||
|
type: "build",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user