feat(notifications): enhance build success notifications to include custom notification support

This commit is contained in:
ChristoferMendes
2025-09-26 17:05:59 -03:00
parent 2ec495b2f2
commit 0e2f1e2832
@@ -6,6 +6,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,
@@ -36,7 +37,7 @@ export const sendBuildSuccessNotifications = async ({
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: and( where: and(
eq(notifications.appDeploy, true), eq(notifications.appDeploy, true),
eq(notifications.organizationId, organizationId), eq(notifications.organizationId, organizationId)
), ),
with: { with: {
email: true, email: true,
@@ -45,11 +46,13 @@ export const sendBuildSuccessNotifications = 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(
@@ -59,7 +62,7 @@ export const sendBuildSuccessNotifications = async ({
applicationType, applicationType,
buildLink, buildLink,
date: date.toLocaleString(), date: date.toLocaleString(),
}), })
).catch(); ).catch();
await sendEmailNotification(email, "Build success for dokploy", template); await sendEmailNotification(email, "Build success for dokploy", template);
} }
@@ -124,7 +127,7 @@ export const sendBuildSuccessNotifications = async ({
`${decorate("⚙️", `Application: ${applicationName}`)}` + `${decorate("⚙️", `Application: ${applicationName}`)}` +
`${decorate("❔", `Type: ${applicationType}`)}` + `${decorate("❔", `Type: ${applicationType}`)}` +
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` + `${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
`${decorate("🔗", `Build details:\n${buildLink}`)}`, `${decorate("🔗", `Build details:\n${buildLink}`)}`
); );
} }
@@ -137,14 +140,14 @@ export const sendBuildSuccessNotifications = async ({
`🛠Project: ${projectName}\n` + `🛠Project: ${projectName}\n` +
`⚙️Application: ${applicationName}\n` + `⚙️Application: ${applicationName}\n` +
`❔Type: ${applicationType}\n` + `❔Type: ${applicationType}\n` +
`🕒Date: ${date.toLocaleString()}`, `🕒Date: ${date.toLocaleString()}`
); );
} }
if (telegram) { if (telegram) {
const chunkArray = <T>(array: T[], chunkSize: number): T[][] => const chunkArray = <T>(array: T[], chunkSize: number): T[][] =>
Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) => Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) =>
array.slice(i * chunkSize, i * chunkSize + chunkSize), array.slice(i * chunkSize, i * chunkSize + chunkSize)
); );
const inlineButton = [ const inlineButton = [
@@ -158,14 +161,17 @@ export const sendBuildSuccessNotifications = async ({
chunk.map((data) => ({ chunk.map((data) => ({
text: data.host, text: data.host,
url: `${data.https ? "https" : "http"}://${data.host}`, url: `${data.https ? "https" : "http"}://${data.host}`,
})), }))
), ),
]; ];
await sendTelegramNotification( await sendTelegramNotification(
telegram, telegram,
`<b>✅ Build Success</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")}`, `<b>✅ Build Success</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")}`,
inlineButton
); );
} }
@@ -210,5 +216,21 @@ export const sendBuildSuccessNotifications = async ({
], ],
}); });
} }
if (custom) {
await sendCustomNotification(custom, {
title: "Build Success",
message: "Build completed successfully",
projectName,
applicationName,
applicationType,
buildLink,
timestamp: date.toISOString(),
date: date.toLocaleString(),
domains: domains.map((domain) => domain.host).join(", "),
status: "success",
type: "build",
});
}
} }
}; };