diff --git a/server/notification-providers/telegram.js b/server/notification-providers/telegram.js index c5bbb1909..a8f15d107 100644 --- a/server/notification-providers/telegram.js +++ b/server/notification-providers/telegram.js @@ -1,5 +1,6 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); +const { Liquid } = require("liquidjs"); class Telegram extends NotificationProvider { name = "telegram"; @@ -22,6 +23,24 @@ class Telegram extends NotificationProvider { params.message_thread_id = notification.telegramMessageThreadID; } + if (notification.telegramUseTemplate) { + const engine = new Liquid(); + const tpl = engine.parse(notification.telegramTemplate); + + params.text = await engine.render( + tpl, + { + msg, + heartbeatJSON, + monitorJSON + } + ); + + if (notification.telegramTemplateParseMode !== "plain") { + params.parse_mode = notification.telegramTemplateParseMode; + } + } + await axios.get(`${url}/bot${notification.telegramBotToken}/sendMessage`, { params: params, }); diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index a072c3ed3..04b49ed00 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -32,7 +32,63 @@

{{ $t("telegramMessageThreadIDDescription") }}

+ +
+
+ + +
+ +
+ {{ $t("telegramUseTemplateDescription") }} +
+
+ + + +
@@ -63,6 +119,17 @@ export default { components: { HiddenInput, }, + computed: { + telegramMessageTemplatePlaceholder() { + return this.$t("Example:", [ + ` +Uptime Kuma Alert{% if monitorJSON %} - {{ monitorJSON['name'] }}{% endif %} + +{{ msg }} + `, + ]); + } + }, methods: { /** * Get the URL for telegram updates @@ -115,3 +182,9 @@ export default { } }; + + diff --git a/src/lang/en.json b/src/lang/en.json index 64958cdc6..86e24d348 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -421,6 +421,9 @@ "telegramSendSilentlyDescription": "Sends the message silently. Users will receive a notification with no sound.", "telegramProtectContent": "Protect Forwarding/Saving", "telegramProtectContentDescription": "If enabled, the bot messages in Telegram will be protected from forwarding and saving.", + "telegramUseTemplate": "Use custom message template", + "telegramUseTemplateDescription": "If enabled, the message will be sent using a custom template.", + "telegramTemplateFormatDescription": "See Telegram {0} for more details on formatting.", "supportTelegramChatID": "Support Direct Chat / Group / Channel's Chat ID", "wayToGetTelegramChatID": "You can get your chat ID by sending a message to the bot and going to this URL to view the chat_id:", "YOUR BOT TOKEN HERE": "YOUR BOT TOKEN HERE", @@ -1053,5 +1056,9 @@ "SendGrid API Key": "SendGrid API Key", "Separate multiple email addresses with commas": "Separate multiple email addresses with commas", "YZJ Webhook URL": "YZJ Webhook URL", - "YZJ Robot Token": "YZJ Robot token" + "YZJ Robot Token": "YZJ Robot token", + "Separate multiple email addresses with commas": "Separate multiple email addresses with commas", + "Plain Text": "Plain Text", + "Template": "Template", + "Template Format": "Template Format" }