Merge pull request #793 from 190km/discord-notifications

style: improved discord webhooks notifications style
This commit is contained in:
Mauricio Siu
2024-12-02 22:01:59 -06:00
committed by GitHub
6 changed files with 101 additions and 38 deletions

View File

@@ -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) {

View File

@@ -59,31 +59,46 @@ export const sendBuildErrorNotifications = async ({
if (discord) {
await sendDiscordNotification(discord, {
title: "⚠️ Build Failed",
color: 0xff0000,
title: "> `⚠️` - Build Failed",
color: 0xed4245,
fields: [
{
name: "Project",
name: "`🛠️`・Project",
value: projectName,
inline: true,
},
{
name: "Application",
name: "`⚙️`・Application",
value: applicationName,
inline: true,
},
{
name: "Type",
name: "`❔`・Type",
value: applicationType,
inline: true,
},
{
name: "Error",
value: errorMessage,
name: "`📅`・Date",
value: date.toLocaleDateString(),
inline: true,
},
{
name: "Build Link",
value: buildLink,
name: "`⌚`・Time",
value: date.toLocaleTimeString(),
inline: true,
},
{
name: "`❓`・Type",
value: "Failed",
inline: true,
},
{
name: "`⚠️`・Error Message",
value: `\`\`\`${errorMessage}\`\`\``,
},
{
name: "`🧷`・Build Link",
value: `[Click here to access build link](${buildLink})`,
},
],
timestamp: date.toISOString(),

View File

@@ -57,27 +57,42 @@ export const sendBuildSuccessNotifications = async ({
if (discord) {
await sendDiscordNotification(discord, {
title: " Build Success",
color: 0x00ff00,
title: "> `✅` - Build Success",
color: 0x57f287,
fields: [
{
name: "Project",
name: "`🛠️`・Project",
value: projectName,
inline: true,
},
{
name: "Application",
name: "`⚙️`・Application",
value: applicationName,
inline: true,
},
{
name: "Type",
name: "`❔`・Application Type",
value: applicationType,
inline: true,
},
{
name: "Build Link",
value: buildLink,
name: "`📅`・Date",
value: date.toLocaleDateString(),
inline: true,
},
{
name: "`⌚`・Time",
value: date.toLocaleTimeString(),
inline: true,
},
{
name: "`❓`・Type",
value: "Successful",
inline: true,
},
{
name: "`🧷`・Build Link",
value: `[Click here to access build link](${buildLink})`,
},
],
timestamp: date.toISOString(),

View File

@@ -64,39 +64,45 @@ 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",
name: "`🛠️`・Project",
value: projectName,
inline: true,
},
{
name: "Application",
name: "`⚙️`・Application",
value: applicationName,
inline: true,
},
{
name: "Type",
name: "`❔`・Database",
value: databaseType,
inline: true,
},
{
name: "Time",
value: date.toLocaleString(),
name: "`📅`・Date",
value: date.toLocaleDateString(),
inline: true,
},
{
name: "Type",
value: type,
name: "`⌚`・Time",
value: date.toLocaleTimeString(),
inline: true,
},
{
name: "`❓`・Type",
value: type.replace("error", "Failed").replace("success", "Successful"),
inline: true,
},
...(type === "error" && errorMessage
? [
{
name: "Error Message",
value: errorMessage,
name: "`⚠️`・Error Message",
value: `\`\`\`${errorMessage}\`\`\``,
},
]
: []),

View File

@@ -45,12 +45,28 @@ 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: "`📅`・Date",
value: date.toLocaleDateString(),
inline: true,
},
{
name: "`⌚`・Time",
value: date.toLocaleTimeString(),
inline: true,
},
{
name: "`❓`・Type",
value: "Successful",
inline: true,
},
{
name: "`📜`・Message",
value: `\`\`\`${message}\`\`\``,
},
],
timestamp: date.toISOString(),

View File

@@ -34,12 +34,22 @@ 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: "`📅`・Date",
value: date.toLocaleDateString(),
inline: true,
},
{
name: "`⌚`・Time",
value: date.toLocaleTimeString(),
inline: true,
},
{
name: "`❓`・Type",
value: "Successful",
inline: true,
},
],