diff --git a/packages/server/src/utils/notifications/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index 44937f646..0362e87f3 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -41,233 +41,233 @@ export const sendDokployRestartNotifications = async () => { for (const notification of notificationList) { const { - email, - resend, - discord, - telegram, - slack, - gotify, - ntfy, - custom, - lark, - pushover, - teams, - } = notification; + email, + resend, + discord, + telegram, + slack, + gotify, + ntfy, + custom, + lark, + pushover, + teams, + } = notification; - try { - if (email || resend) { - const template = await renderAsync( - DokployRestartEmail({ date: date.toLocaleString() }), - ).catch(); + try { + if (email || resend) { + const template = await renderAsync( + DokployRestartEmail({ date: date.toLocaleString() }), + ).catch(); - if (email) { - await sendEmailNotification( - email, - "Dokploy Server Restarted", - template, - ); + if (email) { + await sendEmailNotification( + email, + "Dokploy Server Restarted", + template, + ); + } + + if (resend) { + await sendResendNotification( + resend, + "Dokploy Server Restarted", + template, + ); + } } - if (resend) { - await sendResendNotification( - resend, - "Dokploy Server Restarted", - template, - ); - } - } + if (discord) { + const decorate = (decoration: string, text: string) => + `${discord.decoration ? decoration : ""} ${text}`.trim(); - if (discord) { - const decorate = (decoration: string, text: string) => - `${discord.decoration ? decoration : ""} ${text}`.trim(); - - await sendDiscordNotification(discord, { - title: decorate(">", "`βœ…` Dokploy Server Restarted"), - color: 0x57f287, - fields: [ - { - name: decorate("`πŸ“…`", "Date"), - value: ``, - inline: true, - }, - { - name: decorate("`⌚`", "Time"), - value: ``, - inline: true, - }, - { - name: decorate("`❓`", "Type"), - value: "Successful", - inline: true, - }, - ], - timestamp: date.toISOString(), - footer: { - text: "Dokploy Restart Notification", - }, - }); - } - - if (gotify) { - const decorate = (decoration: string, text: string) => - `${gotify.decoration ? decoration : ""} ${text}\n`; - await sendGotifyNotification( - gotify, - decorate("βœ…", "Dokploy Server Restarted"), - `${decorate("πŸ•’", `Date: ${date.toLocaleString()}`)}`, - ); - } - - if (ntfy) { - await sendNtfyNotification( - ntfy, - "Dokploy Server Restarted", - "white_check_mark", - "", - `πŸ•’Date: ${date.toLocaleString()}`, - ); - } - - if (telegram) { - await sendTelegramNotification( - telegram, - `βœ… Dokploy Server Restarted\n\nDate: ${format( - date, - "PP", - )}\nTime: ${format(date, "pp")}`, - ); - } - - if (slack) { - const { channel } = slack; - await sendSlackNotification(slack, { - channel: channel, - attachments: [ - { - color: "#00FF00", - pretext: ":white_check_mark: *Dokploy Server Restarted*", - fields: [ - { - title: "Time", - value: date.toLocaleString(), - short: true, - }, - ], - }, - ], - }); - } - - if (custom) { - try { - await sendCustomNotification(custom, { - title: "Dokploy Server Restarted", - message: "Dokploy server has been restarted successfully", + await sendDiscordNotification(discord, { + title: decorate(">", "`βœ…` Dokploy Server Restarted"), + color: 0x57f287, + fields: [ + { + name: decorate("`πŸ“…`", "Date"), + value: ``, + inline: true, + }, + { + name: decorate("`⌚`", "Time"), + value: ``, + inline: true, + }, + { + name: decorate("`❓`", "Type"), + value: "Successful", + inline: true, + }, + ], timestamp: date.toISOString(), - date: date.toLocaleString(), - status: "success", - type: "dokploy-restart", + footer: { + text: "Dokploy Restart Notification", + }, }); - } catch (error) { - console.log(error); } - } - if (lark) { - await sendLarkNotification(lark, { - msg_type: "interactive", - card: { - schema: "2.0", - config: { - update_multi: true, - style: { - text_size: { - normal_v2: { - default: "normal", - pc: "normal", - mobile: "heading", + if (gotify) { + const decorate = (decoration: string, text: string) => + `${gotify.decoration ? decoration : ""} ${text}\n`; + await sendGotifyNotification( + gotify, + decorate("βœ…", "Dokploy Server Restarted"), + `${decorate("πŸ•’", `Date: ${date.toLocaleString()}`)}`, + ); + } + + if (ntfy) { + await sendNtfyNotification( + ntfy, + "Dokploy Server Restarted", + "white_check_mark", + "", + `πŸ•’Date: ${date.toLocaleString()}`, + ); + } + + if (telegram) { + await sendTelegramNotification( + telegram, + `βœ… Dokploy Server Restarted\n\nDate: ${format( + date, + "PP", + )}\nTime: ${format(date, "pp")}`, + ); + } + + if (slack) { + const { channel } = slack; + await sendSlackNotification(slack, { + channel: channel, + attachments: [ + { + color: "#00FF00", + pretext: ":white_check_mark: *Dokploy Server Restarted*", + fields: [ + { + title: "Time", + value: date.toLocaleString(), + short: true, + }, + ], + }, + ], + }); + } + + if (custom) { + try { + await sendCustomNotification(custom, { + title: "Dokploy Server Restarted", + message: "Dokploy server has been restarted successfully", + timestamp: date.toISOString(), + date: date.toLocaleString(), + status: "success", + type: "dokploy-restart", + }); + } catch (error) { + console.log(error); + } + } + + if (lark) { + await sendLarkNotification(lark, { + msg_type: "interactive", + card: { + schema: "2.0", + config: { + update_multi: true, + style: { + text_size: { + normal_v2: { + default: "normal", + pc: "normal", + mobile: "heading", + }, }, }, }, - }, - header: { - title: { - tag: "plain_text", - content: "βœ… Dokploy Server Restarted", - }, - subtitle: { - tag: "plain_text", - content: "", - }, - template: "green", - padding: "12px 12px 12px 12px", - }, - body: { - direction: "vertical", - padding: "12px 12px 12px 12px", - elements: [ - { - tag: "column_set", - columns: [ - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: "**Status:**\nSuccessful", - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: `**Restart Time:**\n${format( - date, - "PP pp", - )}`, - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - ], + header: { + title: { + tag: "plain_text", + content: "βœ… Dokploy Server Restarted", }, - ], + subtitle: { + tag: "plain_text", + content: "", + }, + template: "green", + padding: "12px 12px 12px 12px", + }, + body: { + direction: "vertical", + padding: "12px 12px 12px 12px", + elements: [ + { + tag: "column_set", + columns: [ + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: "**Status:**\nSuccessful", + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: `**Restart Time:**\n${format( + date, + "PP pp", + )}`, + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + ], + }, + ], + }, }, - }, - }); - } + }); + } - if (pushover) { - await sendPushoverNotification( - pushover, - "Dokploy Server Restarted", - `Date: ${date.toLocaleString()}`, - ); - } + if (pushover) { + await sendPushoverNotification( + pushover, + "Dokploy Server Restarted", + `Date: ${date.toLocaleString()}`, + ); + } - if (teams) { - await sendTeamsNotification(teams, { - title: "βœ… Dokploy Server Restarted", - facts: [ - { name: "Status", value: "Successful" }, - { name: "Restart Time", value: format(date, "PP pp") }, - ], - }); + if (teams) { + await sendTeamsNotification(teams, { + title: "βœ… Dokploy Server Restarted", + facts: [ + { name: "Status", value: "Successful" }, + { name: "Restart Time", value: format(date, "PP pp") }, + ], + }); + } + } catch (error) { + console.log(error); } - } catch (error) { - console.log(error); - } } } catch (error) { console.error("[Dokploy] Restart notifications failed:", error);