mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Refactor notification sending in Dokploy restart process to include error handling for Discord, Gotify, Telegram, and Slack notifications.
This commit is contained in:
@@ -40,68 +40,84 @@ export const sendDokployRestartNotifications = async () => {
|
|||||||
const decorate = (decoration: string, text: string) =>
|
const decorate = (decoration: string, text: string) =>
|
||||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||||
|
|
||||||
await sendDiscordNotification(discord, {
|
try {
|
||||||
title: decorate(">", "`✅` Dokploy Server Restarted"),
|
await sendDiscordNotification(discord, {
|
||||||
color: 0x57f287,
|
title: decorate(">", "`✅` Dokploy Server Restarted"),
|
||||||
fields: [
|
color: 0x57f287,
|
||||||
{
|
fields: [
|
||||||
name: decorate("`📅`", "Date"),
|
{
|
||||||
value: `<t:${unixDate}:D>`,
|
name: decorate("`📅`", "Date"),
|
||||||
inline: true,
|
value: `<t:${unixDate}:D>`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: decorate("`⌚`", "Time"),
|
||||||
|
value: `<t:${unixDate}:t>`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: decorate("`❓`", "Type"),
|
||||||
|
value: "Successful",
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
timestamp: date.toISOString(),
|
||||||
|
footer: {
|
||||||
|
text: "Dokploy Restart Notification",
|
||||||
},
|
},
|
||||||
{
|
});
|
||||||
name: decorate("`⌚`", "Time"),
|
} catch (error) {
|
||||||
value: `<t:${unixDate}:t>`,
|
console.log(error);
|
||||||
inline: true,
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
name: decorate("`❓`", "Type"),
|
|
||||||
value: "Successful",
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
timestamp: date.toISOString(),
|
|
||||||
footer: {
|
|
||||||
text: "Dokploy Restart Notification",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gotify) {
|
if (gotify) {
|
||||||
const decorate = (decoration: string, text: string) =>
|
const decorate = (decoration: string, text: string) =>
|
||||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||||
await sendGotifyNotification(
|
try {
|
||||||
gotify,
|
await sendGotifyNotification(
|
||||||
decorate("✅", "Dokploy Server Restarted"),
|
gotify,
|
||||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}`,
|
decorate("✅", "Dokploy Server Restarted"),
|
||||||
);
|
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}`,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (telegram) {
|
if (telegram) {
|
||||||
await sendTelegramNotification(
|
try {
|
||||||
telegram,
|
await sendTelegramNotification(
|
||||||
`<b>✅ Dokploy Server Restarted</b>\n\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
telegram,
|
||||||
);
|
`<b>✅ Dokploy Server Restarted</b>\n\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slack) {
|
if (slack) {
|
||||||
const { channel } = slack;
|
const { channel } = slack;
|
||||||
await sendSlackNotification(slack, {
|
try {
|
||||||
channel: channel,
|
await sendSlackNotification(slack, {
|
||||||
attachments: [
|
channel: channel,
|
||||||
{
|
attachments: [
|
||||||
color: "#00FF00",
|
{
|
||||||
pretext: ":white_check_mark: *Dokploy Server Restarted*",
|
color: "#00FF00",
|
||||||
fields: [
|
pretext: ":white_check_mark: *Dokploy Server Restarted*",
|
||||||
{
|
fields: [
|
||||||
title: "Time",
|
{
|
||||||
value: date.toLocaleString(),
|
title: "Time",
|
||||||
short: true,
|
value: date.toLocaleString(),
|
||||||
},
|
short: true,
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
});
|
],
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user