From f5578da0276e82ef4aeea67b7affec75f8236045 Mon Sep 17 00:00:00 2001 From: Epifeny Date: Tue, 27 Jan 2026 03:18:07 +0200 Subject: [PATCH] feat(ntfy): add custom title and message templates for notifications (#6804) Co-authored-by: epifeny Co-authored-by: Frank Elsinga --- server/notification-providers/ntfy.js | 42 +++++++++++++++++++--- src/components/notifications/Ntfy.vue | 52 +++++++++++++++++++++++++++ src/lang/en.json | 10 +++++- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/server/notification-providers/ntfy.js b/server/notification-providers/ntfy.js index d88199b3a..ebe5a1709 100644 --- a/server/notification-providers/ntfy.js +++ b/server/notification-providers/ntfy.js @@ -33,10 +33,27 @@ class Ntfy extends NotificationProvider { config = this.getAxiosConfigWithProxy(config); // If heartbeatJSON is null, assume non monitoring notification (Certificate warning) or testing. if (heartbeatJSON == null) { + // Default values for test notification + let title = (monitorJSON?.name || notification.ntfytopic) + " [Uptime-Kuma]"; + let message = msg; + + // Apply custom templates from notification settings if enabled + if (notification.ntfyUseTemplate) { + const customTitle = notification.ntfyCustomTitle?.trim() || ""; + if (customTitle !== "") { + title = await this.renderTemplate(customTitle, msg, monitorJSON, heartbeatJSON); + } + + const customMessage = notification.ntfyCustomMessage?.trim() || ""; + if (customMessage !== "") { + message = await this.renderTemplate(customMessage, msg, monitorJSON, heartbeatJSON); + } + } + let ntfyTestData = { topic: notification.ntfytopic, - title: (monitorJSON?.name || notification.ntfytopic) + " [Uptime-Kuma]", - message: msg, + title: title, + message: message, priority: notification.ntfyPriority, tags: ["test_tube"], }; @@ -70,11 +87,28 @@ class Ntfy extends NotificationProvider { tags = tags.concat(monitorTagNames); } + // Default values + let title = monitorJSON.name + " " + status + " [Uptime-Kuma]"; + let message = heartbeatJSON.msg; + + // Apply custom templates from notification settings if enabled + if (notification.ntfyUseTemplate) { + const customTitle = notification.ntfyCustomTitle?.trim() || ""; + const customMessage = notification.ntfyCustomMessage?.trim() || ""; + + if (customTitle !== "") { + title = await this.renderTemplate(customTitle, msg, monitorJSON, heartbeatJSON); + } + if (customMessage !== "") { + message = await this.renderTemplate(customMessage, msg, monitorJSON, heartbeatJSON); + } + } + let data = { topic: notification.ntfytopic, - message: heartbeatJSON.msg, + message: message, priority: priority, - title: monitorJSON.name + " " + status + " [Uptime-Kuma]", + title: title, tags: tags, }; diff --git a/src/components/notifications/Ntfy.vue b/src/components/notifications/Ntfy.vue index fb5491b91..fb094f6ac 100644 --- a/src/components/notifications/Ntfy.vue +++ b/src/components/notifications/Ntfy.vue @@ -102,14 +102,59 @@ {{ $t("ntfyCallHelptext") }} + +
+
+ + +
+
+ {{ $t("ntfyUseTemplateDescription") }} +
+
+ +
+
+ + +
{{ $t("ntfyNotificationTemplateFallback") }}
+
+ +
+ + +
{{ $t("ntfyNotificationTemplateFallback") }}
+
+
diff --git a/src/lang/en.json b/src/lang/en.json index dc3eef268..9726b498f 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -259,7 +259,10 @@ "Content Type": "Content Type", "webhookJsonDesc": "{0} is good for any modern HTTP servers such as Express.js", "webhookFormDataDesc": "{multipart} is good for PHP. The JSON will need to be parsed with {decodeFunction}", - "liquidIntroduction": "Templatability is achieved via the Liquid templating language. Please refer to the {0} for usage instructions. These are the available variables:", + "liquidIntroduction": "Templatability is achieved via the Liquid templating language. Please refer to the {0} for usage instructions.", + "templateAvailableVariables": "Available variables", + "example": "Example", + "Result": "Result", "templateMsg": "message of the notification", "templateHeartbeatJSON": "object describing the heartbeat", "templateMonitorJSON": "object describing the monitor", @@ -980,6 +983,11 @@ "ntfyUsernameAndPassword": "Username and Password", "ntfyCall": "Phone Call", "ntfyCallHelptext": "Make a phone call when alert fires. Set to 'yes' to use your first verified number, or enter a specific phone number (e.g. +12223334444). Requires ntfy Pro and a verified phone number.", + "ntfyUseTemplate": "Customize notification templates", + "ntfyUseTemplateDescription": "Enable this to customize notification titles and messages using LiquidJS templating", + "ntfyCustomTitle": "Custom Title Template", + "ntfyCustomMessage": "Custom Message Template", + "ntfyNotificationTemplateFallback": "Leave blank to use the default Uptime Kuma format", "twilioAccountSID": "Account SID", "twilioApiKey": "Api Key (optional)", "twilioApiKeyHelptext": "The API key is optional but recommended. You can provide either Account SID and AuthToken from the may TwilioConsole page or Account SID and the pair of Api Key and Api Key secret",