[autofix.ci] apply automated fixes

This commit is contained in:
autofix-ci[bot]
2026-01-28 13:54:40 +03:30
committed by mhbdev
parent ba8a334fbe
commit 43228fc51b
5 changed files with 1631 additions and 1631 deletions
@@ -1,12 +1,12 @@
import { db } from "@dokploy/server/db"; import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed"; import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed";
import { renderAsync } from "@react-email/components"; 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, sendCustomNotification,
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
sendGotifyNotification, sendGotifyNotification,
sendLarkNotification, sendLarkNotification,
@@ -16,46 +16,46 @@ import {
sendSlackNotification, sendSlackNotification,
sendTelegramNotification, sendTelegramNotification,
} from "./utils"; } from "./utils";
interface Props { interface Props {
projectName: string; projectName: string;
applicationName: string; applicationName: string;
applicationType: string; applicationType: string;
errorMessage: string; errorMessage: string;
buildLink: string; buildLink: string;
organizationId: string; organizationId: string;
} }
export const sendBuildErrorNotifications = async ({ export const sendBuildErrorNotifications = async ({
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
errorMessage, errorMessage,
buildLink, buildLink,
organizationId, organizationId,
}: Props) => { }: Props) => {
const date = new Date(); const date = new Date();
const unixDate = ~~(Number(date) / 1000); const unixDate = ~~(Number(date) / 1000);
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,
discord: true, discord: true,
telegram: true, telegram: true,
slack: true, slack: true,
resend: true, resend: true,
gotify: true, gotify: true,
ntfy: true, ntfy: true,
custom: true, custom: true,
lark: true, lark: true,
pushover: true, pushover: true,
}, },
}); });
for (const notification of notificationList) { for (const notification of notificationList) {
const { const {
email, email,
resend, resend,
@@ -68,322 +68,322 @@ export const sendBuildErrorNotifications = async ({
lark, lark,
pushover, pushover,
} = notification; } = notification;
try { try {
if (email || resend) { if (email || resend) {
const template = await renderAsync( const template = await renderAsync(
BuildFailedEmail({ BuildFailedEmail({
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
errorMessage: errorMessage, errorMessage: errorMessage,
buildLink, buildLink,
date: date.toLocaleString(), date: date.toLocaleString(),
}), }),
).catch(); ).catch();
if (email) { if (email) {
await sendEmailNotification( await sendEmailNotification(
email, email,
"Build failed for dokploy", "Build failed for dokploy",
template, template,
); );
} }
if (resend) { if (resend) {
await sendResendNotification( await sendResendNotification(
resend, resend,
"Build failed for dokploy", "Build failed for dokploy",
template, template,
); );
} }
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim(); `${discord.decoration ? decoration : ""} ${text}`.trim();
const limitCharacter = 800; const limitCharacter = 800;
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter); const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: decorate(">", "`⚠️` Build Failed"), title: decorate(">", "`⚠️` Build Failed"),
color: 0xed4245, color: 0xed4245,
fields: [ fields: [
{ {
name: decorate("`🛠️`", "Project"), name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: decorate("`⚙️`", "Application"), name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: decorate("`❔`", "Type"), name: decorate("`❔`", "Type"),
value: applicationType, value: applicationType,
inline: true, inline: true,
}, },
{ {
name: decorate("`📅`", "Date"), name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`⌚`", "Time"), name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`❓`", "Type"), name: decorate("`❓`", "Type"),
value: "Failed", value: "Failed",
inline: true, inline: true,
}, },
{ {
name: decorate("`⚠️`", "Error Message"), name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${truncatedErrorMessage}\`\`\``, value: `\`\`\`${truncatedErrorMessage}\`\`\``,
}, },
{ {
name: decorate("`🧷`", "Build Link"), name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`, value: `[Click here to access build link](${buildLink})`,
}, },
], ],
timestamp: date.toISOString(), timestamp: date.toISOString(),
footer: { footer: {
text: "Dokploy Build Notification", text: "Dokploy Build Notification",
}, },
}); });
} }
if (gotify) { if (gotify) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${gotify.decoration ? decoration : ""} ${text}\n`; `${gotify.decoration ? decoration : ""} ${text}\n`;
await sendGotifyNotification( await sendGotifyNotification(
gotify, gotify,
decorate("⚠️", "Build Failed"), decorate("⚠️", "Build Failed"),
`${decorate("🛠️", `Project: ${projectName}`)}` + `${decorate("🛠️", `Project: ${projectName}`)}` +
`${decorate("⚙️", `Application: ${applicationName}`)}` + `${decorate("⚙️", `Application: ${applicationName}`)}` +
`${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}`)}`,
); );
} }
if (ntfy) { if (ntfy) {
await sendNtfyNotification( await sendNtfyNotification(
ntfy, ntfy,
"Build Failed", "Build Failed",
"warning", "warning",
`view, Build details, ${buildLink}, clear=true;`, `view, Build details, ${buildLink}, clear=true;`,
`🛠️Project: ${projectName}\n` + `🛠️Project: ${projectName}\n` +
`⚙️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}`,
); );
} }
if (telegram) { if (telegram) {
const inlineButton = [ const inlineButton = [
[ [
{ {
text: "Deployment Logs", text: "Deployment Logs",
url: buildLink, url: buildLink,
}, },
], ],
]; ];
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(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`,
inlineButton, inlineButton,
); );
} }
if (slack) { if (slack) {
const { channel } = slack; const { channel } = slack;
await sendSlackNotification(slack, { await sendSlackNotification(slack, {
channel: channel, channel: channel,
attachments: [ attachments: [
{ {
color: "#FF0000", color: "#FF0000",
pretext: ":warning: *Build Failed*", pretext: ":warning: *Build Failed*",
fields: [ fields: [
{ {
title: "Project", title: "Project",
value: projectName, value: projectName,
short: true, short: true,
}, },
{ {
title: "Application", title: "Application",
value: applicationName, value: applicationName,
short: true, short: true,
}, },
{ {
title: "Type", title: "Type",
value: applicationType, value: applicationType,
short: true, short: true,
}, },
{ {
title: "Time", title: "Time",
value: date.toLocaleString(), value: date.toLocaleString(),
short: true, short: true,
}, },
{ {
title: "Error", title: "Error",
value: `\`\`\`${errorMessage}\`\`\``, value: `\`\`\`${errorMessage}\`\`\``,
short: false, short: false,
}, },
], ],
actions: [ actions: [
{ {
type: "button", type: "button",
text: "View Build Details", text: "View Build Details",
url: buildLink, url: buildLink,
}, },
], ],
}, },
], ],
}); });
} }
if (custom) { if (custom) {
await sendCustomNotification(custom, { await sendCustomNotification(custom, {
title: "Build Error", title: "Build Error",
message: "Build failed with errors", message: "Build failed with errors",
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
errorMessage, errorMessage,
buildLink, buildLink,
timestamp: date.toISOString(), timestamp: date.toISOString(),
date: date.toLocaleString(), date: date.toLocaleString(),
status: "error", status: "error",
type: "build", type: "build",
}); });
} }
if (lark) { if (lark) {
const limitCharacter = 800; const limitCharacter = 800;
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter); const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
await sendLarkNotification(lark, { await sendLarkNotification(lark, {
msg_type: "interactive", msg_type: "interactive",
card: { card: {
schema: "2.0", schema: "2.0",
config: { config: {
update_multi: true, update_multi: true,
style: { style: {
text_size: { text_size: {
normal_v2: { normal_v2: {
default: "normal", default: "normal",
pc: "normal", pc: "normal",
mobile: "heading", mobile: "heading",
}, },
}, },
}, },
}, },
header: { header: {
title: { title: {
tag: "plain_text", tag: "plain_text",
content: "⚠️ Build Failed", content: "⚠️ Build Failed",
}, },
subtitle: { subtitle: {
tag: "plain_text", tag: "plain_text",
content: "", content: "",
}, },
template: "red", template: "red",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
}, },
body: { body: {
direction: "vertical", direction: "vertical",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
elements: [ elements: [
{ {
tag: "column_set", tag: "column_set",
columns: [ columns: [
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Project:**\n${projectName}`, content: `**Project:**\n${projectName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Type:**\n${applicationType}`, content: `**Type:**\n${applicationType}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``, content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Application:**\n${applicationName}`, content: `**Application:**\n${applicationName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Date:**\n${format(date, "PP pp")}`, content: `**Date:**\n${format(date, "PP pp")}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
], ],
}, },
{ {
tag: "button", tag: "button",
text: { text: {
tag: "plain_text", tag: "plain_text",
content: "View Build Details", content: "View Build Details",
}, },
type: "danger", type: "danger",
width: "default", width: "default",
size: "medium", size: "medium",
behaviors: [ behaviors: [
{ {
type: "open_url", type: "open_url",
default_url: buildLink, default_url: buildLink,
pc_url: "", pc_url: "",
ios_url: "", ios_url: "",
android_url: "", android_url: "",
}, },
], ],
margin: "0px 0px 0px 0px", margin: "0px 0px 0px 0px",
}, },
], ],
}, },
}, },
}); });
} }
if (pushover) { if (pushover) {
await sendPushoverNotification( await sendPushoverNotification(
pushover, pushover,
"Build Failed", "Build Failed",
`Project: ${projectName}\nApplication: ${applicationName}\nType: ${applicationType}\nDate: ${date.toLocaleString()}\nError: ${errorMessage}`, `Project: ${projectName}\nApplication: ${applicationName}\nType: ${applicationType}\nDate: ${date.toLocaleString()}\nError: ${errorMessage}`,
); );
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
}; };
@@ -1,13 +1,13 @@
import { db } from "@dokploy/server/db"; import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success"; import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success";
import type { Domain } from "@dokploy/server/services/domain"; import type { Domain } from "@dokploy/server/services/domain";
import { renderAsync } from "@react-email/components"; 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, sendCustomNotification,
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
sendGotifyNotification, sendGotifyNotification,
sendLarkNotification, sendLarkNotification,
@@ -17,48 +17,48 @@ import {
sendSlackNotification, sendSlackNotification,
sendTelegramNotification, sendTelegramNotification,
} from "./utils"; } from "./utils";
interface Props { interface Props {
projectName: string; projectName: string;
applicationName: string; applicationName: string;
applicationType: string; applicationType: string;
buildLink: string; buildLink: string;
organizationId: string; organizationId: string;
domains: Domain[]; domains: Domain[];
environmentName: string; environmentName: string;
} }
export const sendBuildSuccessNotifications = async ({ export const sendBuildSuccessNotifications = async ({
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
buildLink, buildLink,
organizationId, organizationId,
domains, domains,
environmentName, environmentName,
}: Props) => { }: Props) => {
const date = new Date(); const date = new Date();
const unixDate = ~~(Number(date) / 1000); const unixDate = ~~(Number(date) / 1000);
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,
discord: true, discord: true,
telegram: true, telegram: true,
slack: true, slack: true,
resend: true, resend: true,
gotify: true, gotify: true,
ntfy: true, ntfy: true,
custom: true, custom: true,
lark: true, lark: true,
pushover: true, pushover: true,
}, },
}); });
for (const notification of notificationList) { for (const notification of notificationList) {
const { const {
email, email,
resend, resend,
@@ -71,333 +71,333 @@ export const sendBuildSuccessNotifications = async ({
lark, lark,
pushover, pushover,
} = notification; } = notification;
try { try {
if (email || resend) { if (email || resend) {
const template = await renderAsync( const template = await renderAsync(
BuildSuccessEmail({ BuildSuccessEmail({
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
buildLink, buildLink,
date: date.toLocaleString(), date: date.toLocaleString(),
environmentName, environmentName,
}), }),
).catch(); ).catch();
if (email) { if (email) {
await sendEmailNotification( await sendEmailNotification(
email, email,
"Build success for dokploy", "Build success for dokploy",
template, template,
); );
} }
if (resend) { if (resend) {
await sendResendNotification( await sendResendNotification(
resend, resend,
"Build success for dokploy", "Build success for dokploy",
template, template,
); );
} }
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim(); `${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: decorate(">", "`✅` Build Successes"), title: decorate(">", "`✅` Build Successes"),
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: decorate("`🛠️`", "Project"), name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: decorate("`⚙️`", "Application"), name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: decorate("`🌍`", "Environment"), name: decorate("`🌍`", "Environment"),
value: environmentName, value: environmentName,
inline: true, inline: true,
}, },
{ {
name: decorate("`❔`", "Type"), name: decorate("`❔`", "Type"),
value: applicationType, value: applicationType,
inline: true, inline: true,
}, },
{ {
name: decorate("`📅`", "Date"), name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`⌚`", "Time"), name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`❓`", "Type"), name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },
{ {
name: decorate("`🧷`", "Build Link"), name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`, value: `[Click here to access build link](${buildLink})`,
}, },
], ],
timestamp: date.toISOString(), timestamp: date.toISOString(),
footer: { footer: {
text: "Dokploy Build Notification", text: "Dokploy Build Notification",
}, },
}); });
} }
if (gotify) { if (gotify) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${gotify.decoration ? decoration : ""} ${text}\n`; `${gotify.decoration ? decoration : ""} ${text}\n`;
await sendGotifyNotification( await sendGotifyNotification(
gotify, gotify,
decorate("✅", "Build Success"), decorate("✅", "Build Success"),
`${decorate("🛠️", `Project: ${projectName}`)}` + `${decorate("🛠️", `Project: ${projectName}`)}` +
`${decorate("⚙️", `Application: ${applicationName}`)}` + `${decorate("⚙️", `Application: ${applicationName}`)}` +
`${decorate("🌍", `Environment: ${environmentName}`)}` + `${decorate("🌍", `Environment: ${environmentName}`)}` +
`${decorate("❔", `Type: ${applicationType}`)}` + `${decorate("❔", `Type: ${applicationType}`)}` +
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` + `${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
`${decorate("🔗", `Build details:\n${buildLink}`)}`, `${decorate("🔗", `Build details:\n${buildLink}`)}`,
); );
} }
if (ntfy) { if (ntfy) {
await sendNtfyNotification( await sendNtfyNotification(
ntfy, ntfy,
"Build Success", "Build Success",
"white_check_mark", "white_check_mark",
`view, Build details, ${buildLink}, clear=true;`, `view, Build details, ${buildLink}, clear=true;`,
`🛠Project: ${projectName}\n` + `🛠Project: ${projectName}\n` +
`⚙️Application: ${applicationName}\n` + `⚙️Application: ${applicationName}\n` +
`🌍Environment: ${environmentName}\n` + `🌍Environment: ${environmentName}\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 = [
[ [
{ {
text: "Deployment Logs", text: "Deployment Logs",
url: buildLink, url: buildLink,
}, },
], ],
...chunkArray(domains, 2).map((chunk) => ...chunkArray(domains, 2).map((chunk) =>
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>Environment:</b> ${environmentName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format( `<b>✅ Build Success</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Environment:</b> ${environmentName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(
date, date,
"PP", "PP",
)}\n<b>Time:</b> ${format(date, "pp")}`, )}\n<b>Time:</b> ${format(date, "pp")}`,
inlineButton, inlineButton,
); );
} }
if (slack) { if (slack) {
const { channel } = slack; const { channel } = slack;
await sendSlackNotification(slack, { await sendSlackNotification(slack, {
channel: channel, channel: channel,
attachments: [ attachments: [
{ {
color: "#00FF00", color: "#00FF00",
pretext: ":white_check_mark: *Build Success*", pretext: ":white_check_mark: *Build Success*",
fields: [ fields: [
{ {
title: "Project", title: "Project",
value: projectName, value: projectName,
short: true, short: true,
}, },
{ {
title: "Application", title: "Application",
value: applicationName, value: applicationName,
short: true, short: true,
}, },
{ {
title: "Environment", title: "Environment",
value: environmentName, value: environmentName,
short: true, short: true,
}, },
{ {
title: "Type", title: "Type",
value: applicationType, value: applicationType,
short: true, short: true,
}, },
{ {
title: "Time", title: "Time",
value: date.toLocaleString(), value: date.toLocaleString(),
short: true, short: true,
}, },
], ],
actions: [ actions: [
{ {
type: "button", type: "button",
text: "View Build Details", text: "View Build Details",
url: buildLink, url: buildLink,
}, },
], ],
}, },
], ],
}); });
} }
if (custom) { if (custom) {
await sendCustomNotification(custom, { await sendCustomNotification(custom, {
title: "Build Success", title: "Build Success",
message: "Build completed successfully", message: "Build completed successfully",
projectName, projectName,
applicationName, applicationName,
applicationType, applicationType,
buildLink, buildLink,
timestamp: date.toISOString(), timestamp: date.toISOString(),
date: date.toLocaleString(), date: date.toLocaleString(),
domains: domains.map((domain) => domain.host).join(", "), domains: domains.map((domain) => domain.host).join(", "),
status: "success", status: "success",
type: "build", type: "build",
}); });
} }
if (lark) { if (lark) {
await sendLarkNotification(lark, { await sendLarkNotification(lark, {
msg_type: "interactive", msg_type: "interactive",
card: { card: {
schema: "2.0", schema: "2.0",
config: { config: {
update_multi: true, update_multi: true,
style: { style: {
text_size: { text_size: {
normal_v2: { normal_v2: {
default: "normal", default: "normal",
pc: "normal", pc: "normal",
mobile: "heading", mobile: "heading",
}, },
}, },
}, },
}, },
header: { header: {
title: { title: {
tag: "plain_text", tag: "plain_text",
content: "✅ Build Success", content: "✅ Build Success",
}, },
subtitle: { subtitle: {
tag: "plain_text", tag: "plain_text",
content: "", content: "",
}, },
template: "green", template: "green",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
}, },
body: { body: {
direction: "vertical", direction: "vertical",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
elements: [ elements: [
{ {
tag: "column_set", tag: "column_set",
columns: [ columns: [
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Project:**\n${projectName}`, content: `**Project:**\n${projectName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Environment:**\n${environmentName}`, content: `**Environment:**\n${environmentName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Type:**\n${applicationType}`, content: `**Type:**\n${applicationType}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Application:**\n${applicationName}`, content: `**Application:**\n${applicationName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Date:**\n${format(date, "PP pp")}`, content: `**Date:**\n${format(date, "PP pp")}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
], ],
}, },
{ {
tag: "button", tag: "button",
text: { text: {
tag: "plain_text", tag: "plain_text",
content: "View Build Details", content: "View Build Details",
}, },
type: "primary", type: "primary",
width: "default", width: "default",
size: "medium", size: "medium",
behaviors: [ behaviors: [
{ {
type: "open_url", type: "open_url",
default_url: buildLink, default_url: buildLink,
pc_url: "", pc_url: "",
ios_url: "", ios_url: "",
android_url: "", android_url: "",
}, },
], ],
margin: "0px 0px 0px 0px", margin: "0px 0px 0px 0px",
}, },
], ],
}, },
}, },
}); });
} }
if (pushover) { if (pushover) {
await sendPushoverNotification( await sendPushoverNotification(
pushover, pushover,
"Build Success", "Build Success",
`Project: ${projectName}\nApplication: ${applicationName}\nEnvironment: ${environmentName}\nType: ${applicationType}\nDate: ${date.toLocaleString()}`, `Project: ${projectName}\nApplication: ${applicationName}\nEnvironment: ${environmentName}\nType: ${applicationType}\nDate: ${date.toLocaleString()}`,
); );
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
}; };
@@ -1,12 +1,12 @@
import { db } from "@dokploy/server/db"; import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup"; import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup";
import { renderAsync } from "@react-email/components"; 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, sendCustomNotification,
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
sendGotifyNotification, sendGotifyNotification,
sendLarkNotification, sendLarkNotification,
@@ -16,46 +16,46 @@ import {
sendSlackNotification, sendSlackNotification,
sendTelegramNotification, sendTelegramNotification,
} from "./utils"; } from "./utils";
export const sendDatabaseBackupNotifications = async ({ export const sendDatabaseBackupNotifications = async ({
projectName, projectName,
applicationName, applicationName,
databaseType, databaseType,
type, type,
errorMessage, errorMessage,
organizationId, organizationId,
databaseName, databaseName,
}: { }: {
projectName: string; projectName: string;
applicationName: string; applicationName: string;
databaseType: "postgres" | "mysql" | "mongodb" | "mariadb"; databaseType: "postgres" | "mysql" | "mongodb" | "mariadb";
type: "error" | "success"; type: "error" | "success";
organizationId: string; organizationId: string;
errorMessage?: string; errorMessage?: string;
databaseName: string; databaseName: string;
}) => { }) => {
const date = new Date(); const date = new Date();
const unixDate = ~~(Number(date) / 1000); const unixDate = ~~(Number(date) / 1000);
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: and( where: and(
eq(notifications.databaseBackup, true), eq(notifications.databaseBackup, true),
eq(notifications.organizationId, organizationId), eq(notifications.organizationId, organizationId),
), ),
with: { with: {
email: true, email: true,
discord: true, discord: true,
telegram: true, telegram: true,
slack: true, slack: true,
resend: true, resend: true,
gotify: true, gotify: true,
ntfy: true, ntfy: true,
custom: true, custom: true,
lark: true, lark: true,
pushover: true, pushover: true,
}, },
}); });
for (const notification of notificationList) { for (const notification of notificationList) {
const { const {
email, email,
resend, resend,
@@ -68,350 +68,350 @@ export const sendDatabaseBackupNotifications = async ({
lark, lark,
pushover, pushover,
} = notification; } = notification;
try { try {
if (email || resend) { if (email || resend) {
const template = await renderAsync( const template = await renderAsync(
DatabaseBackupEmail({ DatabaseBackupEmail({
projectName, projectName,
applicationName, applicationName,
databaseType, databaseType,
type, type,
errorMessage, errorMessage,
date: date.toLocaleString(), date: date.toLocaleString(),
}), }),
).catch(); ).catch();
if (email) { if (email) {
await sendEmailNotification( await sendEmailNotification(
email, email,
"Database backup for dokploy", "Database backup for dokploy",
template, template,
); );
} }
if (resend) { if (resend) {
await sendResendNotification( await sendResendNotification(
resend, resend,
"Database backup for dokploy", "Database backup for dokploy",
template, template,
); );
} }
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim(); `${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: title:
type === "success" type === "success"
? decorate(">", "`✅` Database Backup Successful") ? decorate(">", "`✅` Database Backup Successful")
: decorate(">", "`❌` Database Backup Failed"), : decorate(">", "`❌` Database Backup Failed"),
color: type === "success" ? 0x57f287 : 0xed4245, color: type === "success" ? 0x57f287 : 0xed4245,
fields: [ fields: [
{ {
name: decorate("`🛠️`", "Project"), name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: decorate("`⚙️`", "Application"), name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: decorate("`❔`", "Database"), name: decorate("`❔`", "Database"),
value: databaseType, value: databaseType,
inline: true, inline: true,
}, },
{ {
name: decorate("`📂`", "Database Name"), name: decorate("`📂`", "Database Name"),
value: databaseName, value: databaseName,
inline: true, inline: true,
}, },
{ {
name: decorate("`📅`", "Date"), name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`⌚`", "Time"), name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`❓`", "Type"), name: decorate("`❓`", "Type"),
value: type value: type
.replace("error", "Failed") .replace("error", "Failed")
.replace("success", "Successful"), .replace("success", "Successful"),
inline: true, inline: true,
}, },
...(type === "error" && errorMessage ...(type === "error" && errorMessage
? [ ? [
{ {
name: decorate("`⚠️`", "Error Message"), name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${errorMessage}\`\`\``, value: `\`\`\`${errorMessage}\`\`\``,
}, },
] ]
: []), : []),
], ],
timestamp: date.toISOString(), timestamp: date.toISOString(),
footer: { footer: {
text: "Dokploy Database Backup Notification", text: "Dokploy Database Backup Notification",
}, },
}); });
} }
if (gotify) { if (gotify) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${gotify.decoration ? decoration : ""} ${text}\n`; `${gotify.decoration ? decoration : ""} ${text}\n`;
await sendGotifyNotification( await sendGotifyNotification(
gotify, gotify,
decorate( decorate(
type === "success" ? "✅" : "❌", type === "success" ? "✅" : "❌",
`Database Backup ${type === "success" ? "Successful" : "Failed"}`, `Database Backup ${type === "success" ? "Successful" : "Failed"}`,
), ),
`${decorate("🛠️", `Project: ${projectName}`)}` + `${decorate("🛠️", `Project: ${projectName}`)}` +
`${decorate("⚙️", `Application: ${applicationName}`)}` + `${decorate("⚙️", `Application: ${applicationName}`)}` +
`${decorate("❔", `Type: ${databaseType}`)}` + `${decorate("❔", `Type: ${databaseType}`)}` +
`${decorate("📂", `Database Name: ${databaseName}`)}` + `${decorate("📂", `Database Name: ${databaseName}`)}` +
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` + `${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
`${type === "error" && errorMessage ? decorate("❌", `Error:\n${errorMessage}`) : ""}`, `${type === "error" && errorMessage ? decorate("❌", `Error:\n${errorMessage}`) : ""}`,
); );
} }
if (ntfy) { if (ntfy) {
await sendNtfyNotification( await sendNtfyNotification(
ntfy, ntfy,
`Database Backup ${type === "success" ? "Successful" : "Failed"}`, `Database Backup ${type === "success" ? "Successful" : "Failed"}`,
`${type === "success" ? "white_check_mark" : "x"}`, `${type === "success" ? "white_check_mark" : "x"}`,
"", "",
`🛠Project: ${projectName}\n` + `🛠Project: ${projectName}\n` +
`⚙️Application: ${applicationName}\n` + `⚙️Application: ${applicationName}\n` +
`❔Type: ${databaseType}\n` + `❔Type: ${databaseType}\n` +
`📂Database Name: ${databaseName}` + `📂Database Name: ${databaseName}` +
`🕒Date: ${date.toLocaleString()}\n` + `🕒Date: ${date.toLocaleString()}\n` +
`${type === "error" && errorMessage ? `❌Error:\n${errorMessage}` : ""}`, `${type === "error" && errorMessage ? `❌Error:\n${errorMessage}` : ""}`,
); );
} }
if (telegram) { if (telegram) {
const isError = type === "error" && errorMessage; const isError = type === "error" && errorMessage;
const statusEmoji = type === "success" ? "✅" : "❌"; const statusEmoji = type === "success" ? "✅" : "❌";
const typeStatus = type === "success" ? "Successful" : "Failed"; const typeStatus = type === "success" ? "Successful" : "Failed";
const errorMsg = isError const errorMsg = isError
? `\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>` ? `\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`
: ""; : "";
const messageText = `<b>${statusEmoji} Database Backup ${typeStatus}</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${databaseType}\n<b>Database Name:</b> ${databaseName}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}${isError ? errorMsg : ""}`; const messageText = `<b>${statusEmoji} Database Backup ${typeStatus}</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${databaseType}\n<b>Database Name:</b> ${databaseName}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}${isError ? errorMsg : ""}`;
await sendTelegramNotification(telegram, messageText); await sendTelegramNotification(telegram, messageText);
} }
if (slack) { if (slack) {
const { channel } = slack; const { channel } = slack;
await sendSlackNotification(slack, { await sendSlackNotification(slack, {
channel: channel, channel: channel,
attachments: [ attachments: [
{ {
color: type === "success" ? "#00FF00" : "#FF0000", color: type === "success" ? "#00FF00" : "#FF0000",
pretext: pretext:
type === "success" type === "success"
? ":white_check_mark: *Database Backup Successful*" ? ":white_check_mark: *Database Backup Successful*"
: ":x: *Database Backup Failed*", : ":x: *Database Backup Failed*",
fields: [ fields: [
...(type === "error" && errorMessage ...(type === "error" && errorMessage
? [ ? [
{ {
title: "Error Message", title: "Error Message",
value: errorMessage, value: errorMessage,
short: false, short: false,
}, },
] ]
: []), : []),
{ {
title: "Project", title: "Project",
value: projectName, value: projectName,
short: true, short: true,
}, },
{ {
title: "Application", title: "Application",
value: applicationName, value: applicationName,
short: true, short: true,
}, },
{ {
title: "Type", title: "Type",
value: databaseType, value: databaseType,
short: true, short: true,
}, },
{ {
title: "Database Name", title: "Database Name",
value: databaseName, value: databaseName,
}, },
{ {
title: "Time", title: "Time",
value: date.toLocaleString(), value: date.toLocaleString(),
short: true, short: true,
}, },
{ {
title: "Type", title: "Type",
value: type, value: type,
}, },
{ {
title: "Status", title: "Status",
value: type === "success" ? "Successful" : "Failed", value: type === "success" ? "Successful" : "Failed",
}, },
], ],
}, },
], ],
}); });
} }
if (custom) { if (custom) {
await sendCustomNotification(custom, { await sendCustomNotification(custom, {
title: `Database Backup ${type === "success" ? "Successful" : "Failed"}`, title: `Database Backup ${type === "success" ? "Successful" : "Failed"}`,
message: message:
type === "success" type === "success"
? "Database backup completed successfully" ? "Database backup completed successfully"
: "Database backup failed", : "Database backup failed",
projectName, projectName,
applicationName, applicationName,
databaseType, databaseType,
databaseName, databaseName,
type, type,
errorMessage: errorMessage || "", errorMessage: errorMessage || "",
timestamp: date.toISOString(), timestamp: date.toISOString(),
date: date.toLocaleString(), date: date.toLocaleString(),
status: type, status: type,
}); });
} }
if (lark) { if (lark) {
const limitCharacter = 800; const limitCharacter = 800;
const truncatedErrorMessage = const truncatedErrorMessage =
errorMessage && errorMessage.length > limitCharacter errorMessage && errorMessage.length > limitCharacter
? errorMessage.substring(0, limitCharacter) ? errorMessage.substring(0, limitCharacter)
: errorMessage; : errorMessage;
await sendLarkNotification(lark, { await sendLarkNotification(lark, {
msg_type: "interactive", msg_type: "interactive",
card: { card: {
schema: "2.0", schema: "2.0",
config: { config: {
update_multi: true, update_multi: true,
style: { style: {
text_size: { text_size: {
normal_v2: { normal_v2: {
default: "normal", default: "normal",
pc: "normal", pc: "normal",
mobile: "heading", mobile: "heading",
}, },
}, },
}, },
}, },
header: { header: {
title: { title: {
tag: "plain_text", tag: "plain_text",
content: content:
type === "success" type === "success"
? "✅ Database Backup Successful" ? "✅ Database Backup Successful"
: "❌ Database Backup Failed", : "❌ Database Backup Failed",
}, },
subtitle: { subtitle: {
tag: "plain_text", tag: "plain_text",
content: "", content: "",
}, },
template: type === "success" ? "green" : "red", template: type === "success" ? "green" : "red",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
}, },
body: { body: {
direction: "vertical", direction: "vertical",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
elements: [ elements: [
{ {
tag: "column_set", tag: "column_set",
columns: [ columns: [
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Project:**\n${projectName}`, content: `**Project:**\n${projectName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Database Type:**\n${databaseType}`, content: `**Database Type:**\n${databaseType}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Status:**\n${type === "success" ? "Successful" : "Failed"}`, content: `**Status:**\n${type === "success" ? "Successful" : "Failed"}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Application:**\n${applicationName}`, content: `**Application:**\n${applicationName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Database Name:**\n${databaseName}`, content: `**Database Name:**\n${databaseName}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Date:**\n${format(date, "PP pp")}`, content: `**Date:**\n${format(date, "PP pp")}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
], ],
}, },
...(type === "error" && truncatedErrorMessage ...(type === "error" && truncatedErrorMessage
? [ ? [
{ {
tag: "markdown", tag: "markdown",
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``, content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
] ]
: []), : []),
], ],
}, },
}, },
}); });
} }
if (pushover) { if (pushover) {
await sendPushoverNotification( await sendPushoverNotification(
pushover, pushover,
`Database Backup ${type === "success" ? "Successful" : "Failed"}`, `Database Backup ${type === "success" ? "Successful" : "Failed"}`,
`Project: ${projectName}\nApplication: ${applicationName}\nDatabase: ${databaseType}\nDatabase Name: ${databaseName}\nDate: ${date.toLocaleString()}${type === "error" && errorMessage ? `\nError: ${errorMessage}` : ""}`, `Project: ${projectName}\nApplication: ${applicationName}\nDatabase: ${databaseType}\nDatabase Name: ${databaseName}\nDate: ${date.toLocaleString()}${type === "error" && errorMessage ? `\nError: ${errorMessage}` : ""}`,
); );
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
}; };
@@ -1,12 +1,12 @@
import { db } from "@dokploy/server/db"; import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup"; import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup";
import { renderAsync } from "@react-email/components"; 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, sendCustomNotification,
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
sendGotifyNotification, sendGotifyNotification,
sendLarkNotification, sendLarkNotification,
@@ -16,33 +16,33 @@ import {
sendSlackNotification, sendSlackNotification,
sendTelegramNotification, sendTelegramNotification,
} from "./utils"; } from "./utils";
export const sendDockerCleanupNotifications = async ( export const sendDockerCleanupNotifications = async (
organizationId: string, organizationId: string,
message = "Docker cleanup for dokploy", message = "Docker cleanup for dokploy",
) => { ) => {
const date = new Date(); const date = new Date();
const unixDate = ~~(Number(date) / 1000); const unixDate = ~~(Number(date) / 1000);
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: and( where: and(
eq(notifications.dockerCleanup, true), eq(notifications.dockerCleanup, true),
eq(notifications.organizationId, organizationId), eq(notifications.organizationId, organizationId),
), ),
with: { with: {
email: true, email: true,
discord: true, discord: true,
telegram: true, telegram: true,
slack: true, slack: true,
resend: true, resend: true,
gotify: true, gotify: true,
ntfy: true, ntfy: true,
custom: true, custom: true,
lark: true, lark: true,
pushover: true, pushover: true,
}, },
}); });
for (const notification of notificationList) { for (const notification of notificationList) {
const { const {
email, email,
resend, resend,
@@ -55,215 +55,215 @@ export const sendDockerCleanupNotifications = async (
lark, lark,
pushover, pushover,
} = notification; } = notification;
try { try {
if (email || resend) { if (email || resend) {
const template = await renderAsync( const template = await renderAsync(
DockerCleanupEmail({ message, date: date.toLocaleString() }), DockerCleanupEmail({ message, date: date.toLocaleString() }),
).catch(); ).catch();
if (email) { if (email) {
await sendEmailNotification( await sendEmailNotification(
email, email,
"Docker cleanup for dokploy", "Docker cleanup for dokploy",
template, template,
); );
} }
if (resend) { if (resend) {
await sendResendNotification( await sendResendNotification(
resend, resend,
"Docker cleanup for dokploy", "Docker cleanup for dokploy",
template, template,
); );
} }
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim(); `${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: decorate(">", "`✅` Docker Cleanup"), title: decorate(">", "`✅` Docker Cleanup"),
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: decorate("`📅`", "Date"), name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`⌚`", "Time"), name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`❓`", "Type"), name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },
{ {
name: decorate("`📜`", "Message"), name: decorate("`📜`", "Message"),
value: `\`\`\`${message}\`\`\``, value: `\`\`\`${message}\`\`\``,
}, },
], ],
timestamp: date.toISOString(), timestamp: date.toISOString(),
footer: { footer: {
text: "Dokploy Docker Cleanup Notification", text: "Dokploy Docker Cleanup Notification",
}, },
}); });
} }
if (gotify) { if (gotify) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${gotify.decoration ? decoration : ""} ${text}\n`; `${gotify.decoration ? decoration : ""} ${text}\n`;
await sendGotifyNotification( await sendGotifyNotification(
gotify, gotify,
decorate("✅", "Docker Cleanup"), decorate("✅", "Docker Cleanup"),
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` + `${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
`${decorate("📜", `Message:\n${message}`)}`, `${decorate("📜", `Message:\n${message}`)}`,
); );
} }
if (ntfy) { if (ntfy) {
await sendNtfyNotification( await sendNtfyNotification(
ntfy, ntfy,
"Docker Cleanup", "Docker Cleanup",
"white_check_mark", "white_check_mark",
"", "",
`🕒Date: ${date.toLocaleString()}\n` + `📜Message:\n${message}`, `🕒Date: ${date.toLocaleString()}\n` + `📜Message:\n${message}`,
); );
} }
if (telegram) { if (telegram) {
await sendTelegramNotification( await sendTelegramNotification(
telegram, telegram,
`<b>✅ Docker Cleanup</b>\n\n<b>Message:</b> ${message}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`, `<b>✅ Docker Cleanup</b>\n\n<b>Message:</b> ${message}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
); );
} }
if (slack) { if (slack) {
const { channel } = slack; const { channel } = slack;
await sendSlackNotification(slack, { await sendSlackNotification(slack, {
channel: channel, channel: channel,
attachments: [ attachments: [
{ {
color: "#00FF00", color: "#00FF00",
pretext: ":white_check_mark: *Docker Cleanup*", pretext: ":white_check_mark: *Docker Cleanup*",
fields: [ fields: [
{ {
title: "Message", title: "Message",
value: message, value: message,
}, },
{ {
title: "Time", title: "Time",
value: date.toLocaleString(), value: date.toLocaleString(),
short: true, short: true,
}, },
], ],
}, },
], ],
}); });
} }
if (custom) { if (custom) {
await sendCustomNotification(custom, { await sendCustomNotification(custom, {
title: "Docker Cleanup", title: "Docker Cleanup",
message: "Docker cleanup completed successfully", message: "Docker cleanup completed successfully",
cleanupMessage: message, cleanupMessage: message,
timestamp: date.toISOString(), timestamp: date.toISOString(),
date: date.toLocaleString(), date: date.toLocaleString(),
status: "success", status: "success",
type: "docker-cleanup", type: "docker-cleanup",
}); });
} }
if (lark) { if (lark) {
await sendLarkNotification(lark, { await sendLarkNotification(lark, {
msg_type: "interactive", msg_type: "interactive",
card: { card: {
schema: "2.0", schema: "2.0",
config: { config: {
update_multi: true, update_multi: true,
style: { style: {
text_size: { text_size: {
normal_v2: { normal_v2: {
default: "normal", default: "normal",
pc: "normal", pc: "normal",
mobile: "heading", mobile: "heading",
}, },
}, },
}, },
}, },
header: { header: {
title: { title: {
tag: "plain_text", tag: "plain_text",
content: "✅ Docker Cleanup", content: "✅ Docker Cleanup",
}, },
subtitle: { subtitle: {
tag: "plain_text", tag: "plain_text",
content: "", content: "",
}, },
template: "green", template: "green",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
}, },
body: { body: {
direction: "vertical", direction: "vertical",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
elements: [ elements: [
{ {
tag: "column_set", tag: "column_set",
columns: [ columns: [
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: "**Status:**\nSuccessful", content: "**Status:**\nSuccessful",
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
{ {
tag: "markdown", tag: "markdown",
content: `**Cleanup Details:**\n${message}`, content: `**Cleanup Details:**\n${message}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Date:**\n${format(date, "PP pp")}`, content: `**Date:**\n${format(date, "PP pp")}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
], ],
}, },
], ],
}, },
}, },
}); });
} }
if (pushover) { if (pushover) {
await sendPushoverNotification( await sendPushoverNotification(
pushover, pushover,
"Docker Cleanup", "Docker Cleanup",
`Date: ${date.toLocaleString()}\nMessage: ${message}`, `Date: ${date.toLocaleString()}\nMessage: ${message}`,
); );
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
}; };
@@ -1,12 +1,12 @@
import { db } from "@dokploy/server/db"; import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import DokployRestartEmail from "@dokploy/server/emails/emails/dokploy-restart"; import DokployRestartEmail from "@dokploy/server/emails/emails/dokploy-restart";
import { renderAsync } from "@react-email/components"; import { renderAsync } from "@react-email/components";
import { format } from "date-fns"; import { format } from "date-fns";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { import {
sendCustomNotification, sendCustomNotification,
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
sendGotifyNotification, sendGotifyNotification,
sendLarkNotification, sendLarkNotification,
@@ -16,27 +16,27 @@ import {
sendSlackNotification, sendSlackNotification,
sendTelegramNotification, sendTelegramNotification,
} from "./utils"; } from "./utils";
export const sendDokployRestartNotifications = async () => { export const sendDokployRestartNotifications = async () => {
const date = new Date(); const date = new Date();
const unixDate = ~~(Number(date) / 1000); const unixDate = ~~(Number(date) / 1000);
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: eq(notifications.dokployRestart, true), where: eq(notifications.dokployRestart, true),
with: { with: {
email: true, email: true,
discord: true, discord: true,
telegram: true, telegram: true,
slack: true, slack: true,
resend: true, resend: true,
gotify: true, gotify: true,
ntfy: true, ntfy: true,
custom: true, custom: true,
lark: true, lark: true,
pushover: true, pushover: true,
}, },
}); });
for (const notification of notificationList) { for (const notification of notificationList) {
const { const {
email, email,
resend, resend,
@@ -49,210 +49,210 @@ export const sendDokployRestartNotifications = async () => {
lark, lark,
pushover, pushover,
} = notification; } = notification;
try { try {
if (email || resend) { if (email || resend) {
const template = await renderAsync( const template = await renderAsync(
DokployRestartEmail({ date: date.toLocaleString() }), DokployRestartEmail({ date: date.toLocaleString() }),
).catch(); ).catch();
if (email) { if (email) {
await sendEmailNotification( await sendEmailNotification(
email, email,
"Dokploy Server Restarted", "Dokploy Server Restarted",
template, template,
); );
} }
if (resend) { if (resend) {
await sendResendNotification( await sendResendNotification(
resend, resend,
"Dokploy Server Restarted", "Dokploy Server Restarted",
template, template,
); );
} }
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim(); `${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: decorate(">", "`✅` Dokploy Server Restarted"), title: decorate(">", "`✅` Dokploy Server Restarted"),
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: decorate("`📅`", "Date"), name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`⌚`", "Time"), name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: decorate("`❓`", "Type"), name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },
], ],
timestamp: date.toISOString(), timestamp: date.toISOString(),
footer: { footer: {
text: "Dokploy Restart Notification", text: "Dokploy Restart Notification",
}, },
}); });
} }
if (gotify) { if (gotify) {
const decorate = (decoration: string, text: string) => const decorate = (decoration: string, text: string) =>
`${gotify.decoration ? decoration : ""} ${text}\n`; `${gotify.decoration ? decoration : ""} ${text}\n`;
await sendGotifyNotification( await sendGotifyNotification(
gotify, gotify,
decorate("✅", "Dokploy Server Restarted"), decorate("✅", "Dokploy Server Restarted"),
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}`, `${decorate("🕒", `Date: ${date.toLocaleString()}`)}`,
); );
} }
if (ntfy) { if (ntfy) {
await sendNtfyNotification( await sendNtfyNotification(
ntfy, ntfy,
"Dokploy Server Restarted", "Dokploy Server Restarted",
"white_check_mark", "white_check_mark",
"", "",
`🕒Date: ${date.toLocaleString()}`, `🕒Date: ${date.toLocaleString()}`,
); );
} }
if (telegram) { if (telegram) {
await sendTelegramNotification( await sendTelegramNotification(
telegram, telegram,
`<b>✅ Dokploy Server Restarted</b>\n\n<b>Date:</b> ${format( `<b>✅ Dokploy Server Restarted</b>\n\n<b>Date:</b> ${format(
date, date,
"PP", "PP",
)}\n<b>Time:</b> ${format(date, "pp")}`, )}\n<b>Time:</b> ${format(date, "pp")}`,
); );
} }
if (slack) { if (slack) {
const { channel } = slack; const { channel } = slack;
await sendSlackNotification(slack, { await sendSlackNotification(slack, {
channel: channel, channel: channel,
attachments: [ attachments: [
{ {
color: "#00FF00", color: "#00FF00",
pretext: ":white_check_mark: *Dokploy Server Restarted*", pretext: ":white_check_mark: *Dokploy Server Restarted*",
fields: [ fields: [
{ {
title: "Time", title: "Time",
value: date.toLocaleString(), value: date.toLocaleString(),
short: true, short: true,
}, },
], ],
}, },
], ],
}); });
} }
if (custom) { if (custom) {
try { try {
await sendCustomNotification(custom, { await sendCustomNotification(custom, {
title: "Dokploy Server Restarted", title: "Dokploy Server Restarted",
message: "Dokploy server has been restarted successfully", message: "Dokploy server has been restarted successfully",
timestamp: date.toISOString(), timestamp: date.toISOString(),
date: date.toLocaleString(), date: date.toLocaleString(),
status: "success", status: "success",
type: "dokploy-restart", type: "dokploy-restart",
}); });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
if (lark) { if (lark) {
await sendLarkNotification(lark, { await sendLarkNotification(lark, {
msg_type: "interactive", msg_type: "interactive",
card: { card: {
schema: "2.0", schema: "2.0",
config: { config: {
update_multi: true, update_multi: true,
style: { style: {
text_size: { text_size: {
normal_v2: { normal_v2: {
default: "normal", default: "normal",
pc: "normal", pc: "normal",
mobile: "heading", mobile: "heading",
}, },
}, },
}, },
}, },
header: { header: {
title: { title: {
tag: "plain_text", tag: "plain_text",
content: "✅ Dokploy Server Restarted", content: "✅ Dokploy Server Restarted",
}, },
subtitle: { subtitle: {
tag: "plain_text", tag: "plain_text",
content: "", content: "",
}, },
template: "green", template: "green",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
}, },
body: { body: {
direction: "vertical", direction: "vertical",
padding: "12px 12px 12px 12px", padding: "12px 12px 12px 12px",
elements: [ elements: [
{ {
tag: "column_set", tag: "column_set",
columns: [ columns: [
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: "**Status:**\nSuccessful", content: "**Status:**\nSuccessful",
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
{ {
tag: "column", tag: "column",
width: "weighted", width: "weighted",
elements: [ elements: [
{ {
tag: "markdown", tag: "markdown",
content: `**Restart Time:**\n${format( content: `**Restart Time:**\n${format(
date, date,
"PP pp", "PP pp",
)}`, )}`,
text_align: "left", text_align: "left",
text_size: "normal_v2", text_size: "normal_v2",
}, },
], ],
vertical_align: "top", vertical_align: "top",
weight: 1, weight: 1,
}, },
], ],
}, },
], ],
}, },
}, },
}); });
} }
if (pushover) { if (pushover) {
await sendPushoverNotification( await sendPushoverNotification(
pushover, pushover,
"Dokploy Server Restarted", "Dokploy Server Restarted",
`Date: ${date.toLocaleString()}`, `Date: ${date.toLocaleString()}`,
); );
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
}; };