From a235815a13c494b07ca63b9f4571340a98f0d684 Mon Sep 17 00:00:00 2001 From: 190km Date: Sun, 1 Dec 2024 04:09:19 +0100 Subject: [PATCH 1/2] style: improved discord webhooks notifications --- .../server/api/routers/notification.ts | 5 ++- .../src/utils/notifications/build-error.ts | 22 +++++------ .../src/utils/notifications/build-success.ts | 18 ++++----- .../utils/notifications/database-backup.ts | 39 ++++++++++--------- .../src/utils/notifications/docker-cleanup.ts | 8 ++-- .../utils/notifications/dokploy-restart.ts | 8 ++-- 6 files changed, 51 insertions(+), 49 deletions(-) diff --git a/apps/dokploy/server/api/routers/notification.ts b/apps/dokploy/server/api/routers/notification.ts index 170b7bf2..504e3320 100644 --- a/apps/dokploy/server/api/routers/notification.ts +++ b/apps/dokploy/server/api/routers/notification.ts @@ -188,8 +188,9 @@ export const notificationRouter = createTRPCRouter({ .mutation(async ({ input }) => { try { await sendDiscordNotification(input, { - title: "Test Notification", - description: "Hi, From Dokploy 👋", + title: "> `🤚` - Test Notification", + description: "> Hi, From Dokploy 👋", + color: 0xf3f7f4 }); return true; } catch (error) { diff --git a/packages/server/src/utils/notifications/build-error.ts b/packages/server/src/utils/notifications/build-error.ts index 9fcb0641..a8a7bf25 100644 --- a/packages/server/src/utils/notifications/build-error.ts +++ b/packages/server/src/utils/notifications/build-error.ts @@ -59,30 +59,30 @@ export const sendBuildErrorNotifications = async ({ if (discord) { await sendDiscordNotification(discord, { - title: "⚠️ Build Failed", - color: 0xff0000, + title: "> `⚠️` - Build Failed", + color: 0xed4245, fields: [ { - name: "Project", - value: projectName, + name: "`🛠️`・Project", + value: `\`\`\`${projectName}\`\`\``, inline: true, }, { - name: "Application", - value: applicationName, + name: "`⚙️`・Application", + value: `\`\`\`${applicationName}\`\`\``, inline: true, }, { - name: "Type", - value: applicationType, + name: "`❔`・Type", + value: `\`\`\`${applicationType}\`\`\``, inline: true, }, { - name: "Error", - value: errorMessage, + name: "`⚠️`・Error Message", + value: `\`\`\`${errorMessage}\`\`\``, }, { - name: "Build Link", + name: "`🧷`・Build Link", value: buildLink, }, ], diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 9210eca2..4475bd44 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -57,26 +57,26 @@ export const sendBuildSuccessNotifications = async ({ if (discord) { await sendDiscordNotification(discord, { - title: "✅ Build Success", - color: 0x00ff00, + title: "> `✅` - Build Success", + color: 0x57f287, fields: [ { - name: "Project", - value: projectName, + name: "`🛠️`・Project", + value: `\`\`\`${projectName}\`\`\``, inline: true, }, { - name: "Application", - value: applicationName, + name: "`⚙️`・Application", + value: `\`\`\`${applicationName}\`\`\``, inline: true, }, { - name: "Type", - value: applicationType, + name: "`❔`・Type", + value: `\`\`\`${applicationType}\`\`\``, inline: true, }, { - name: "Build Link", + name: "`🧷`・Build Link", value: buildLink, }, ], diff --git a/packages/server/src/utils/notifications/database-backup.ts b/packages/server/src/utils/notifications/database-backup.ts index c97afa03..63a842ab 100644 --- a/packages/server/src/utils/notifications/database-backup.ts +++ b/packages/server/src/utils/notifications/database-backup.ts @@ -64,39 +64,40 @@ export const sendDatabaseBackupNotifications = async ({ await sendDiscordNotification(discord, { title: type === "success" - ? "✅ Database Backup Successful" - : "❌ Database Backup Failed", - color: type === "success" ? 0x00ff00 : 0xff0000, + ? "> `✅` - Database Backup Successful" + : "> `❌` - Database Backup Failed", + color: type === "success" ? 0x57f287 : 0xed4245, fields: [ { - name: "Project", - value: projectName, + name: "`🛠️`・Project", + value: `\`\`\`${projectName}\`\`\``, + inline: false, + }, + { + name: "`⚙️`・Application", + value: `\`\`\`${applicationName}\`\`\``, inline: true, }, { - name: "Application", - value: applicationName, + name: "`❔`・Type", + value: `\`\`\`${databaseType}\`\`\``, inline: true, }, { - name: "Type", - value: databaseType, - inline: true, + name: "`📅`・Time", + value: `\`\`\`${date.toLocaleString()}\`\`\``, + inline: false, }, { - name: "Time", - value: date.toLocaleString(), - inline: true, - }, - { - name: "Type", - value: type, + name: "`❔`・Type", + value: `\`\`\`${type}\`\`\``, + inline: false, }, ...(type === "error" && errorMessage ? [ { - name: "Error Message", - value: errorMessage, + name: "`⚠️`・Error Message", + value: `\`\`\`${errorMessage}\`\`\``, }, ] : []), diff --git a/packages/server/src/utils/notifications/docker-cleanup.ts b/packages/server/src/utils/notifications/docker-cleanup.ts index a2e09139..68c3f119 100644 --- a/packages/server/src/utils/notifications/docker-cleanup.ts +++ b/packages/server/src/utils/notifications/docker-cleanup.ts @@ -45,12 +45,12 @@ export const sendDockerCleanupNotifications = async ( if (discord) { await sendDiscordNotification(discord, { - title: "✅ Docker Cleanup", - color: 0x00ff00, + title: "> `✅` - Docker Cleanup", + color: 0x57f287, fields: [ { - name: "Message", - value: message, + name: "`📜`・Message", + value: `\`\`\`${message}\`\`\``, }, ], timestamp: date.toISOString(), diff --git a/packages/server/src/utils/notifications/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index 33bc32f0..451044f4 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -34,12 +34,12 @@ export const sendDokployRestartNotifications = async () => { if (discord) { await sendDiscordNotification(discord, { - title: "✅ Dokploy Server Restarted", - color: 0x00ff00, + title: "> `✅` - Dokploy Server Restarted", + color: 0x57f287, fields: [ { - name: "Time", - value: date.toLocaleString(), + name: "`📅`・Time", + value: `\`\`\`${date.toLocaleString()}\`\`\``, inline: true, }, ], From 9a8a40b0f84d329b30ffacc470112197275f5871 Mon Sep 17 00:00:00 2001 From: 190km Date: Sun, 1 Dec 2024 16:37:45 +0100 Subject: [PATCH 2/2] style: removed useless codeblock fields --- .../src/utils/notifications/build-error.ts | 23 +++++++++++++--- .../src/utils/notifications/build-success.ts | 25 +++++++++++++---- .../utils/notifications/database-backup.ts | 27 +++++++++++-------- .../src/utils/notifications/docker-cleanup.ts | 16 +++++++++++ .../utils/notifications/dokploy-restart.ts | 14 ++++++++-- 5 files changed, 83 insertions(+), 22 deletions(-) diff --git a/packages/server/src/utils/notifications/build-error.ts b/packages/server/src/utils/notifications/build-error.ts index a8a7bf25..3c4fd73d 100644 --- a/packages/server/src/utils/notifications/build-error.ts +++ b/packages/server/src/utils/notifications/build-error.ts @@ -64,17 +64,32 @@ export const sendBuildErrorNotifications = async ({ fields: [ { name: "`🛠️`・Project", - value: `\`\`\`${projectName}\`\`\``, + value: projectName, inline: true, }, { name: "`⚙️`・Application", - value: `\`\`\`${applicationName}\`\`\``, + value: applicationName, inline: true, }, { name: "`❔`・Type", - value: `\`\`\`${applicationType}\`\`\``, + value: applicationType, + inline: true, + }, + { + name: "`📅`・Date", + value: date.toLocaleDateString(), + inline: true, + }, + { + name: "`⌚`・Time", + value: date.toLocaleTimeString(), + inline: true, + }, + { + name: "`❓`・Type", + value: "Failed", inline: true, }, { @@ -83,7 +98,7 @@ export const sendBuildErrorNotifications = async ({ }, { name: "`🧷`・Build Link", - value: buildLink, + value: `[Click here to access build link](${buildLink})`, }, ], timestamp: date.toISOString(), diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index 4475bd44..0e09e87d 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -62,22 +62,37 @@ export const sendBuildSuccessNotifications = async ({ fields: [ { name: "`🛠️`・Project", - value: `\`\`\`${projectName}\`\`\``, + value: projectName, inline: true, }, { name: "`⚙️`・Application", - value: `\`\`\`${applicationName}\`\`\``, + value: applicationName, inline: true, }, { - name: "`❔`・Type", - value: `\`\`\`${applicationType}\`\`\``, + name: "`❔`・Application Type", + value: applicationType, + inline: true, + }, + { + name: "`📅`・Date", + value: date.toLocaleDateString(), + inline: true, + }, + { + name: "`⌚`・Time", + value: date.toLocaleTimeString(), + inline: true, + }, + { + name: "`❓`・Type", + value: "Successful", inline: true, }, { name: "`🧷`・Build Link", - value: buildLink, + value: `[Click here to access build link](${buildLink})`, }, ], timestamp: date.toISOString(), diff --git a/packages/server/src/utils/notifications/database-backup.ts b/packages/server/src/utils/notifications/database-backup.ts index 63a842ab..115d8b20 100644 --- a/packages/server/src/utils/notifications/database-backup.ts +++ b/packages/server/src/utils/notifications/database-backup.ts @@ -70,28 +70,33 @@ export const sendDatabaseBackupNotifications = async ({ fields: [ { name: "`🛠️`・Project", - value: `\`\`\`${projectName}\`\`\``, - inline: false, + value: projectName, + inline: true, }, { name: "`⚙️`・Application", - value: `\`\`\`${applicationName}\`\`\``, + value: applicationName, inline: true, }, { - name: "`❔`・Type", - value: `\`\`\`${databaseType}\`\`\``, + name: "`❔`・Database", + value: databaseType, inline: true, }, { - name: "`📅`・Time", - value: `\`\`\`${date.toLocaleString()}\`\`\``, - inline: false, + name: "`📅`・Date", + value: date.toLocaleDateString(), + inline: true, }, { - name: "`❔`・Type", - value: `\`\`\`${type}\`\`\``, - inline: false, + name: "`⌚`・Time", + value: date.toLocaleTimeString(), + inline: true, + }, + { + name: "`❓`・Type", + value: type.replace("error", "Failed").replace("success", "Successful"), + inline: true, }, ...(type === "error" && errorMessage ? [ diff --git a/packages/server/src/utils/notifications/docker-cleanup.ts b/packages/server/src/utils/notifications/docker-cleanup.ts index 68c3f119..31c1c6c9 100644 --- a/packages/server/src/utils/notifications/docker-cleanup.ts +++ b/packages/server/src/utils/notifications/docker-cleanup.ts @@ -48,6 +48,22 @@ export const sendDockerCleanupNotifications = async ( title: "> `✅` - Docker Cleanup", color: 0x57f287, fields: [ + + { + name: "`📅`・Date", + value: date.toLocaleDateString(), + inline: true, + }, + { + name: "`⌚`・Time", + value: date.toLocaleTimeString(), + inline: true, + }, + { + name: "`❓`・Type", + value: "Successful", + inline: true, + }, { name: "`📜`・Message", value: `\`\`\`${message}\`\`\``, diff --git a/packages/server/src/utils/notifications/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index 451044f4..c552e269 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -38,8 +38,18 @@ export const sendDokployRestartNotifications = async () => { color: 0x57f287, fields: [ { - name: "`📅`・Time", - value: `\`\`\`${date.toLocaleString()}\`\`\``, + name: "`📅`・Date", + value: date.toLocaleDateString(), + inline: true, + }, + { + name: "`⌚`・Time", + value: date.toLocaleTimeString(), + inline: true, + }, + { + name: "`❓`・Type", + value: "Successful", inline: true, }, ],