diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index e2ed407fc..068e69b36 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -213,6 +213,7 @@ export const deployApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, + domains: application.domains }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -332,6 +333,7 @@ export const deployRemoteApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, + domains: application.domains }); } catch (error) { // @ts-ignore diff --git a/packages/server/src/services/compose.ts b/packages/server/src/services/compose.ts index 50459c450..8561dd376 100644 --- a/packages/server/src/services/compose.ts +++ b/packages/server/src/services/compose.ts @@ -243,6 +243,7 @@ export const deployCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, + domains: compose.domains, }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -366,6 +367,7 @@ export const deployRemoteCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, + domains: compose.domains, }); } catch (error) { // @ts-ignore diff --git a/packages/server/src/utils/notifications/build-error.ts b/packages/server/src/utils/notifications/build-error.ts index 695b37863..ef4c16cc0 100644 --- a/packages/server/src/utils/notifications/build-error.ts +++ b/packages/server/src/utils/notifications/build-error.ts @@ -3,6 +3,7 @@ import { notifications } from "@dokploy/server/db/schema"; import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed"; import { renderAsync } from "@react-email/components"; import { and, eq } from "drizzle-orm"; +import { format } from "date-fns"; import { sendDiscordNotification, sendEmailNotification, @@ -113,21 +114,19 @@ export const sendBuildErrorNotifications = async ({ } if (telegram) { + const inlineButton = [ + [ + { + text: "Deployment Logs", + url: buildLink, + }, + ], + ]; + await sendTelegramNotification( telegram, - ` - ⚠️ Build Failed - - Project: ${projectName} - Application: ${applicationName} - Type: ${applicationType} - Time: ${date.toLocaleString()} - - Error: -
${errorMessage}
- - Build Details: ${buildLink} - `, + `⚠️ Build Failed\n\nProject: ${projectName}\nApplication: ${applicationName}\nType: ${applicationType}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}\n\nError:\n
${errorMessage}
`, + inlineButton ); } diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 16aa4a588..5467481d4 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -1,8 +1,10 @@ import { db } from "@dokploy/server/db"; import { notifications } from "@dokploy/server/db/schema"; import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success"; +import { Domain } from "@dokploy/server/services/domain"; import { renderAsync } from "@react-email/components"; import { and, eq } from "drizzle-orm"; +import { format } from "date-fns"; import { sendDiscordNotification, sendEmailNotification, @@ -16,6 +18,7 @@ interface Props { applicationType: string; buildLink: string; adminId: string; + domains: Domain[]; } export const sendBuildSuccessNotifications = async ({ @@ -24,6 +27,7 @@ export const sendBuildSuccessNotifications = async ({ applicationType, buildLink, adminId, + domains }: Props) => { const date = new Date(); const unixDate = ~~(Number(date) / 1000); @@ -107,18 +111,29 @@ export const sendBuildSuccessNotifications = async ({ } if (telegram) { + const chunkArray = (array: T[], chunkSize: number): T[][] => + Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) => array.slice(i * chunkSize, i * chunkSize + chunkSize) + ); + + const inlineButton = [ + [ + { + text: "Deployment Logs", + url: buildLink, + }, + ], + ...chunkArray(domains, 2).map((chunk) => + chunk.map((data) => ({ + text: data.host, + url: `${data.https ? "https" : "http"}://${data.host}`, + })) + ), + ]; + await sendTelegramNotification( telegram, - ` - ✅ Build Success - - Project: ${projectName} - Application: ${applicationName} - Type: ${applicationType} - Time: ${date.toLocaleString()} - - Build Details: ${buildLink} - `, + `✅ Build Success\n\nProject: ${projectName}\nApplication: ${applicationName}\nType: ${applicationType}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, + inlineButton ); } diff --git a/packages/server/src/utils/notifications/database-backup.ts b/packages/server/src/utils/notifications/database-backup.ts index 3aec6f3d3..74cbf144d 100644 --- a/packages/server/src/utils/notifications/database-backup.ts +++ b/packages/server/src/utils/notifications/database-backup.ts @@ -3,6 +3,7 @@ import { notifications } from "@dokploy/server/db/schema"; import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup"; import { renderAsync } from "@react-email/components"; import { and, eq } from "drizzle-orm"; +import { format } from "date-fns"; import { sendDiscordNotification, sendEmailNotification, @@ -121,18 +122,14 @@ export const sendDatabaseBackupNotifications = async ({ } if (telegram) { + const isError = type === "error" && errorMessage; + const statusEmoji = type === "success" ? "✅" : "❌"; - const messageText = ` - ${statusEmoji} Database Backup ${type === "success" ? "Successful" : "Failed"} - - Project: ${projectName} - Application: ${applicationName} - Type: ${databaseType} - Time: ${date.toLocaleString()} - - Status: ${type === "success" ? "Successful" : "Failed"} - ${type === "error" && errorMessage ? `Error: ${errorMessage}` : ""} - `; + const typeStatus = type === "success" ? "Successful" : "Failed"; + const errorMsg = isError ? `\n\nError:\n
${errorMessage}
` : ""; + + const messageText = `${statusEmoji} Database Backup ${typeStatus}\n\nProject: ${projectName}\nApplication: ${applicationName}\nType: ${databaseType}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}${isError ? errorMsg : ""}`; + await sendTelegramNotification(telegram, messageText); } diff --git a/packages/server/src/utils/notifications/docker-cleanup.ts b/packages/server/src/utils/notifications/docker-cleanup.ts index c95c79067..adcd569e1 100644 --- a/packages/server/src/utils/notifications/docker-cleanup.ts +++ b/packages/server/src/utils/notifications/docker-cleanup.ts @@ -3,6 +3,7 @@ import { notifications } from "@dokploy/server/db/schema"; import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup"; import { renderAsync } from "@react-email/components"; import { and, eq } from "drizzle-orm"; +import { format } from "date-fns"; import { sendDiscordNotification, sendEmailNotification, @@ -82,11 +83,7 @@ export const sendDockerCleanupNotifications = async ( if (telegram) { await sendTelegramNotification( telegram, - ` - ✅ Docker Cleanup - Message: ${message} - Time: ${date.toLocaleString()} - `, + `✅ Docker Cleanup\n\nMessage: ${message}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}` ); } diff --git a/packages/server/src/utils/notifications/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index 16170349b..484da16d7 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -9,6 +9,7 @@ import { sendSlackNotification, sendTelegramNotification, } from "./utils"; +import { format } from "date-fns"; export const sendDokployRestartNotifications = async () => { const date = new Date(); @@ -67,10 +68,7 @@ export const sendDokployRestartNotifications = async () => { if (telegram) { await sendTelegramNotification( telegram, - ` - ✅ Dokploy Serverd Restarted - Time: ${date.toLocaleString()} - `, + `✅ Dokploy Serverd Restarted\n\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}` ); } diff --git a/packages/server/src/utils/notifications/utils.ts b/packages/server/src/utils/notifications/utils.ts index 2f8324bb1..839643006 100644 --- a/packages/server/src/utils/notifications/utils.ts +++ b/packages/server/src/utils/notifications/utils.ts @@ -55,6 +55,10 @@ export const sendDiscordNotification = async ( export const sendTelegramNotification = async ( connection: typeof telegram.$inferInsert, messageText: string, + inlineButton?: { + text: string; + url: string; + }[][] ) => { try { const url = `https://api.telegram.org/bot${connection.botToken}/sendMessage`; @@ -66,6 +70,9 @@ export const sendTelegramNotification = async ( text: messageText, parse_mode: "HTML", disable_web_page_preview: true, + reply_markup: { + inline_keyboard: inlineButton, + }, }), }); } catch (err) {