From dd3618bfd95e5e6eef5c71ec31a24c5b7d0bdcaf Mon Sep 17 00:00:00 2001 From: shiqocred <90097870+shiqocred@users.noreply.github.com> Date: Sun, 12 Jan 2025 00:55:31 +0700 Subject: [PATCH 1/9] Add inline button telegram (#3) * Update utils.ts add type inline button * Update dokploy-restart.ts fixing format massage and adding [] for inline button type * Update docker-cleanup.ts fixing telegram message * Update database-backup.ts fixing telegram message * Update build-error.ts fixing message and adding button logs view * Update build-success.ts fixing message, adding domains props, adding inline button * Update compose.ts adding get domains compose and send to notif * Update application.ts adding get domains and send it to notif --- packages/server/src/services/application.ts | 4 +++ packages/server/src/services/compose.ts | 4 +++ .../src/utils/notifications/build-error.ts | 25 +++++++------ .../src/utils/notifications/build-success.ts | 36 +++++++++++++------ .../utils/notifications/database-backup.ts | 21 +++++------ .../src/utils/notifications/docker-cleanup.ts | 8 ++--- .../utils/notifications/dokploy-restart.ts | 7 ++-- .../server/src/utils/notifications/utils.ts | 7 ++++ 8 files changed, 68 insertions(+), 44 deletions(-) diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index e2ed407f..fa690952 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -176,6 +176,7 @@ export const deployApplication = async ({ }) => { const application = await findApplicationById(applicationId); const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; + const domains = application.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -213,6 +214,7 @@ export const deployApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, + domains }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -285,6 +287,7 @@ export const deployRemoteApplication = async ({ }) => { const application = await findApplicationById(applicationId); const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; + const domains = application.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -332,6 +335,7 @@ export const deployRemoteApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, + domains }); } catch (error) { // @ts-ignore diff --git a/packages/server/src/services/compose.ts b/packages/server/src/services/compose.ts index 50459c45..2ed3d462 100644 --- a/packages/server/src/services/compose.ts +++ b/packages/server/src/services/compose.ts @@ -209,6 +209,7 @@ export const deployCompose = async ({ const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; + const domains = compose.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -243,6 +244,7 @@ export const deployCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, + domains }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -313,6 +315,7 @@ export const deployRemoteCompose = async ({ const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; + const domains = compose.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -366,6 +369,7 @@ export const deployRemoteCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, + 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 695b3786..ef4c16cc 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 402b0cd2..3bfa18a8 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -16,6 +16,10 @@ interface Props { applicationType: string; buildLink: string; adminId: string; + domains: { + host: string; + https: boolean; + }[]; } export const sendBuildSuccessNotifications = async ({ @@ -24,6 +28,7 @@ export const sendBuildSuccessNotifications = async ({ applicationType, buildLink, adminId, + domains }: Props) => { const date = new Date(); const unixDate = ~~(Number(date) / 1000); @@ -107,18 +112,29 @@ export const sendBuildSuccessNotifications = async ({ } if (telegram) { + const chunkArray =
${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, []); } if (slack) { diff --git a/packages/server/src/utils/notifications/docker-cleanup.ts b/packages/server/src/utils/notifications/docker-cleanup.ts index c95c7906..8623867f 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,8 @@ 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 16170349..ffa838b7 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,8 @@ export const sendDokployRestartNotifications = async () => { if (telegram) { await sendTelegramNotification( telegram, - ` - ✅ Dokploy Serverd Restarted - Time: ${date.toLocaleString()} - `, + `✅ Dokploy Serverd Restarted\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 8327c33d..96301156 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) { From 1d8db07fa1a2841ec899f76eb969d513da908865 Mon Sep 17 00:00:00 2001 From: shiqocred <90097870+shiqocred@users.noreply.github.com> Date: Sun, 12 Jan 2025 01:20:39 +0700 Subject: [PATCH 2/9] Add inline button telegram (#4) * Update utils.ts add type inline button * Update dokploy-restart.ts fixing format massage and adding [] for inline button type * Update docker-cleanup.ts fixing telegram message * Update database-backup.ts fixing telegram message * Update build-error.ts fixing message and adding button logs view * Update build-success.ts fixing message, adding domains props, adding inline button * Update compose.ts adding get domains compose and send to notif * Update application.ts adding get domains and send it to notif * Update build-success.ts fix space * Update dokploy-restart.ts fixing space --- packages/server/src/utils/notifications/build-success.ts | 2 +- packages/server/src/utils/notifications/dokploy-restart.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 3bfa18a8..7b03d0c1 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -133,7 +133,7 @@ export const sendBuildSuccessNotifications = async ({ await sendTelegramNotification( telegram, - `✅ Build Success\n\nProject: ${projectName}\nApplication: ${applicationName}Type: ${applicationType}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, + `✅ 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/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index ffa838b7..7ee50b6a 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -68,7 +68,7 @@ export const sendDokployRestartNotifications = async () => { if (telegram) { await sendTelegramNotification( telegram, - `✅ Dokploy Serverd Restarted\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, + `✅ Dokploy Serverd Restarted\n\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, [] ); } From c0b8a411bd5a75a0cbeba3b7447a8726c2e993ba Mon Sep 17 00:00:00 2001 From: shiqocred <90097870+shiqocred@users.noreply.github.com> Date: Sun, 12 Jan 2025 02:04:10 +0700 Subject: [PATCH 3/9] Update build-success.ts (#5) add format --- packages/server/src/utils/notifications/build-success.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 7b03d0c1..366b4591 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -3,6 +3,7 @@ import { notifications } from "@dokploy/server/db/schema"; import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success"; import { renderAsync } from "@react-email/components"; import { and, eq } from "drizzle-orm"; +import { format } from "date-fns"; import { sendDiscordNotification, sendEmailNotification, From d2094d6d76821b65c95c91bb3c987e5567574364 Mon Sep 17 00:00:00 2001 From: shiqocred <90097870+shiqocred@users.noreply.github.com> Date: Sun, 12 Jan 2025 02:14:09 +0700 Subject: [PATCH 4/9] Update notification.ts (#6) fix router notification --- apps/dokploy/server/api/routers/notification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dokploy/server/api/routers/notification.ts b/apps/dokploy/server/api/routers/notification.ts index f8869503..61a1310e 100644 --- a/apps/dokploy/server/api/routers/notification.ts +++ b/apps/dokploy/server/api/routers/notification.ts @@ -134,7 +134,7 @@ export const notificationRouter = createTRPCRouter({ .input(apiTestTelegramConnection) .mutation(async ({ input }) => { try { - await sendTelegramNotification(input, "Hi, From Dokploy 👋"); + await sendTelegramNotification(input, "Hi, From Dokploy 👋", []); return true; } catch (error) { throw new TRPCError({ From 537950dd9f26aef12b3498845641d259aace3c4f Mon Sep 17 00:00:00 2001 From: shiqocred <90097870+shiqocred@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:13:13 +0700 Subject: [PATCH 5/9] Revision notification (#7) * Update build-success.ts * Update compose.ts * Update application.ts * Update notification.ts * Update utils.ts * Update dokploy-restart.ts * Update docker-cleanup.ts * Update database-backup.ts * Update build-success.ts * Update build-success.ts --- apps/dokploy/server/api/routers/notification.ts | 2 +- packages/server/src/services/application.ts | 6 ++---- packages/server/src/services/compose.ts | 6 ++---- packages/server/src/utils/notifications/build-success.ts | 6 ++---- packages/server/src/utils/notifications/database-backup.ts | 2 +- packages/server/src/utils/notifications/docker-cleanup.ts | 3 +-- packages/server/src/utils/notifications/dokploy-restart.ts | 3 +-- packages/server/src/utils/notifications/utils.ts | 2 +- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/dokploy/server/api/routers/notification.ts b/apps/dokploy/server/api/routers/notification.ts index 61a1310e..f8869503 100644 --- a/apps/dokploy/server/api/routers/notification.ts +++ b/apps/dokploy/server/api/routers/notification.ts @@ -134,7 +134,7 @@ export const notificationRouter = createTRPCRouter({ .input(apiTestTelegramConnection) .mutation(async ({ input }) => { try { - await sendTelegramNotification(input, "Hi, From Dokploy 👋", []); + await sendTelegramNotification(input, "Hi, From Dokploy 👋"); return true; } catch (error) { throw new TRPCError({ diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index fa690952..068e69b3 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -176,7 +176,6 @@ export const deployApplication = async ({ }) => { const application = await findApplicationById(applicationId); const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; - const domains = application.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -214,7 +213,7 @@ export const deployApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, - domains + domains: application.domains }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -287,7 +286,6 @@ export const deployRemoteApplication = async ({ }) => { const application = await findApplicationById(applicationId); const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; - const domains = application.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -335,7 +333,7 @@ export const deployRemoteApplication = async ({ applicationType: "application", buildLink, adminId: application.project.adminId, - domains + domains: application.domains }); } catch (error) { // @ts-ignore diff --git a/packages/server/src/services/compose.ts b/packages/server/src/services/compose.ts index 2ed3d462..8561dd37 100644 --- a/packages/server/src/services/compose.ts +++ b/packages/server/src/services/compose.ts @@ -209,7 +209,6 @@ export const deployCompose = async ({ const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; - const domains = compose.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -244,7 +243,7 @@ export const deployCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, - domains + domains: compose.domains, }); } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); @@ -315,7 +314,6 @@ export const deployRemoteCompose = async ({ const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; - const domains = compose.domains.map(({ host, https }) => ({ host, https })); const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -369,7 +367,7 @@ export const deployRemoteCompose = async ({ applicationType: "compose", buildLink, adminId: compose.project.adminId, - domains + domains: compose.domains, }); } catch (error) { // @ts-ignore diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 366b4591..e30ec37b 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -1,6 +1,7 @@ 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"; @@ -17,10 +18,7 @@ interface Props { applicationType: string; buildLink: string; adminId: string; - domains: { - host: string; - https: boolean; - }[]; + domains: Domain[]; } export const sendBuildSuccessNotifications = async ({ diff --git a/packages/server/src/utils/notifications/database-backup.ts b/packages/server/src/utils/notifications/database-backup.ts index 6594f87c..74cbf144 100644 --- a/packages/server/src/utils/notifications/database-backup.ts +++ b/packages/server/src/utils/notifications/database-backup.ts @@ -130,7 +130,7 @@ export const sendDatabaseBackupNotifications = async ({ 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, []); + await sendTelegramNotification(telegram, messageText); } if (slack) { diff --git a/packages/server/src/utils/notifications/docker-cleanup.ts b/packages/server/src/utils/notifications/docker-cleanup.ts index 8623867f..adcd569e 100644 --- a/packages/server/src/utils/notifications/docker-cleanup.ts +++ b/packages/server/src/utils/notifications/docker-cleanup.ts @@ -83,8 +83,7 @@ export const sendDockerCleanupNotifications = async ( if (telegram) { await sendTelegramNotification( telegram, - `✅ Docker Cleanup\n\nMessage: ${message}\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, - [] + `✅ 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 7ee50b6a..484da16d 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -68,8 +68,7 @@ export const sendDokployRestartNotifications = async () => { if (telegram) { await sendTelegramNotification( telegram, - `✅ Dokploy Serverd Restarted\n\nDate: ${format(date, "PP")}\nTime: ${format(date, "pp")}`, - [] + `✅ 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 96301156..5e16c517 100644 --- a/packages/server/src/utils/notifications/utils.ts +++ b/packages/server/src/utils/notifications/utils.ts @@ -55,7 +55,7 @@ export const sendDiscordNotification = async ( export const sendTelegramNotification = async ( connection: typeof telegram.$inferInsert, messageText: string, - inlineButton: { + inlineButton?: { text: string; url: string; }[][] From 013ee89a56df99f4dc337c130cb494f0d915974b Mon Sep 17 00:00:00 2001 From: thebadking <53491595+thebadking@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:12:11 +0000 Subject: [PATCH 6/9] style: fix tablet and mobile (Create from Template) --- .../components/dashboard/project/add-template.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/dokploy/components/dashboard/project/add-template.tsx b/apps/dokploy/components/dashboard/project/add-template.tsx index 068fc984..0cb5e70c 100644 --- a/apps/dokploy/components/dashboard/project/add-template.tsx +++ b/apps/dokploy/components/dashboard/project/add-template.tsx @@ -114,26 +114,26 @@ export const AddTemplate = ({ projectId }: Props) => {