feat: implement decoration to embeds

This commit is contained in:
João Gabriel 2024-12-22 00:44:25 -03:00
parent 055b59e6fa
commit 870e074825
7 changed files with 64 additions and 45 deletions

View File

@ -363,7 +363,7 @@ export const authRouter = createTRPCRouter({
<a href="${WEBSITE_URL}/reset-password?token=${token}">
Reset Password
</a>
`,
);
}),
@ -505,7 +505,7 @@ export const sendDiscordNotificationWelcome = async (newAdmin: Auth) => {
webhookUrl: process.env.DISCORD_WEBHOOK_URL || "",
},
{
title: " New User Registered",
title: "New User Registered",
color: 0x00ff00,
fields: [
{

View File

@ -187,11 +187,15 @@ export const notificationRouter = createTRPCRouter({
.input(apiTestDiscordConnection)
.mutation(async ({ input }) => {
try {
const decorate = (decoration: string, text: string) =>
`${input.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(input, {
title: "> `🤚` - Test Notification",
description: "> Hi, From Dokploy 👋",
title: decorate(">", "`🤚` - Test Notification"),
description: decorate(">", "Hi, From Dokploy 👋"),
color: 0xf3f7f4,
});
return true;
} catch (error) {
throw new TRPCError({

View File

@ -59,46 +59,49 @@ export const sendBuildErrorNotifications = async ({
}
if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, {
title: "> `⚠️` Build Failed",
title: decorate(">", "`⚠️` Build Failed"),
color: 0xed4245,
fields: [
{
name: "`🛠️` Project",
name: decorate("`🛠️`", "Project"),
value: projectName,
inline: true,
},
{
name: "`⚙️` Application",
name: decorate("`⚙️`", "Application"),
value: applicationName,
inline: true,
},
{
name: "`❔` Type",
name: decorate("`❔`", "Type"),
value: applicationType,
inline: true,
},
{
name: "`📅` Date",
name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`,
inline: true,
},
{
name: "`⌚` Time",
name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`,
inline: true,
},
{
name: "`❓`Type",
name: decorate("`❓`", "Type"),
value: "Failed",
inline: true,
},
{
name: "`⚠️` Error Message",
name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${errorMessage}\`\`\``,
},
{
name: "`🧷` Build Link",
name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`,
},
],
@ -114,15 +117,15 @@ export const sendBuildErrorNotifications = async ({
telegram,
`
<b> Build Failed</b>
<b>Project:</b> ${projectName}
<b>Application:</b> ${applicationName}
<b>Type:</b> ${applicationType}
<b>Time:</b> ${date.toLocaleString()}
<b>Error:</b>
<pre>${errorMessage}</pre>
<b>Build Details:</b> ${buildLink}
`,
);

View File

@ -57,42 +57,45 @@ export const sendBuildSuccessNotifications = async ({
}
if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, {
title: "> `✅` Build Success",
color: 0x57f287,
fields: [
{
name: "`🛠️` Project",
name: decorate("`🛠️`", "Project"),
value: projectName,
inline: true,
},
{
name: "`⚙️` Application",
name: decorate("`⚙️`", "Application"),
value: applicationName,
inline: true,
},
{
name: "`❔` Application Type",
name: decorate("`❔`", "Type"),
value: applicationType,
inline: true,
},
{
name: "`📅` Date",
name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`,
inline: true,
},
{
name: "`⌚` Time",
name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`,
inline: true,
},
{
name: "`❓` Type",
name: decorate("`❓`", "Type"),
value: "Successful",
inline: true,
},
{
name: "`🧷` Build Link",
name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`,
},
],
@ -108,12 +111,12 @@ export const sendBuildSuccessNotifications = async ({
telegram,
`
<b> Build Success</b>
<b>Project:</b> ${projectName}
<b>Application:</b> ${applicationName}
<b>Type:</b> ${applicationType}
<b>Time:</b> ${date.toLocaleString()}
<b>Build Details:</b> ${buildLink}
`,
);

View File

@ -62,40 +62,43 @@ export const sendDatabaseBackupNotifications = async ({
}
if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, {
title:
type === "success"
? "> `✅` Database Backup Successful"
: "> `❌` Database Backup Failed",
? decorate(">", "`✅` Database Backup Successful")
: decorate(">", "`❌` Database Backup Failed"),
color: type === "success" ? 0x57f287 : 0xed4245,
fields: [
{
name: "`🛠️` Project",
name: decorate("`🛠️`", "Project"),
value: projectName,
inline: true,
},
{
name: "`⚙️` Application",
name: decorate("`⚙️`", "Application"),
value: applicationName,
inline: true,
},
{
name: "`❔` Database",
name: decorate("`❔`", "Database"),
value: databaseType,
inline: true,
},
{
name: "`📅` Date",
name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`,
inline: true,
},
{
name: "`⌚` Time",
name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`,
inline: true,
},
{
name: "`❓` Type",
name: decorate("`❓`", "Type"),
value: type
.replace("error", "Failed")
.replace("success", "Successful"),
@ -104,7 +107,7 @@ export const sendDatabaseBackupNotifications = async ({
...(type === "error" && errorMessage
? [
{
name: "`⚠️` Error Message",
name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${errorMessage}\`\`\``,
},
]
@ -121,12 +124,12 @@ export const sendDatabaseBackupNotifications = async ({
const statusEmoji = type === "success" ? "✅" : "❌";
const messageText = `
<b>${statusEmoji} Database Backup ${type === "success" ? "Successful" : "Failed"}</b>
<b>Project:</b> ${projectName}
<b>Application:</b> ${applicationName}
<b>Type:</b> ${databaseType}
<b>Time:</b> ${date.toLocaleString()}
<b>Status:</b> ${type === "success" ? "Successful" : "Failed"}
${type === "error" && errorMessage ? `<b>Error:</b> ${errorMessage}` : ""}
`;

View File

@ -45,27 +45,30 @@ export const sendDockerCleanupNotifications = async (
}
if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, {
title: "> `✅` Docker Cleanup",
title: decorate(">", "`✅` Docker Cleanup"),
color: 0x57f287,
fields: [
{
name: "`📅` Date",
name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`,
inline: true,
},
{
name: "`⌚` Time",
name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`,
inline: true,
},
{
name: "`❓` Type",
name: decorate("`❓`", "Type"),
value: "Successful",
inline: true,
},
{
name: "`📜` Message",
name: decorate("`📜`", "Message"),
value: `\`\`\`${message}\`\`\``,
},
],

View File

@ -34,22 +34,25 @@ export const sendDokployRestartNotifications = async () => {
}
if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, {
title: "> `✅` Dokploy Server Restarted",
title: decorate(">", "`✅` Dokploy Server Restarted"),
color: 0x57f287,
fields: [
{
name: "`📅` Date",
name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`,
inline: true,
},
{
name: "`⌚` Time",
name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`,
inline: true,
},
{
name: "`❓` Type",
name: decorate("`❓`", "Type"),
value: "Successful",
inline: true,
},