Skip to content

fix: escape Telegram MarkdownV2 after template rendering#6579

Merged
CommanderStorm merged 3 commits intolouislam:masterfrom
GivenBY:fix-telegram-markdown-escape
Jan 4, 2026
Merged

fix: escape Telegram MarkdownV2 after template rendering#6579
CommanderStorm merged 3 commits intolouislam:masterfrom
GivenBY:fix-telegram-markdown-escape

Conversation

@GivenBY
Copy link
Copy Markdown
Contributor

@GivenBY GivenBY commented Jan 3, 2026

📝 Summary

This pull request fixes telegram notification failures when using MarkdownV2 together with custom message templates.

currently, template variables such as {{ hostnameOrURL }}, {{ monitorJSON }}, or {{ heartbeatJSON }} may contain characters reserved by telegram MarkdownV2 syntax (e.g. ., -, _, {}, etc.). These characters are not escaped, causing telegram API errors and making templates effectively unusable.

This change ensures that when MarkdownV2 is selected, all template values are safely escaped before sending the message to telegram. This removes the need for users to manually escape content they do not control and aligns behavior with telegram MarkdownV2 specification.

The change is scoped only to the telegram provider and does not affect other providers or parse modes.

📋 Related issues

Resolves #6549

📄 Checklist

Please follow this checklist to avoid unnecessary back and forth (click to expand)
  • ⚠️ If there are Breaking change (a fix or feature that alters existing functionality in a way that could cause issues) I have called them out
  • 🧠 I have disclosed any use of LLMs/AI in this contribution and reviewed all generated content.
    I understand that I am responsible for and able to explain every line of code I submit.
  • 🔍 My code adheres to the style guidelines of this project.
  • ⚠️ My changes generate no new warnings.
  • 📝 I have commented my code, especially in hard-to-understand areas (e.g., using JSDoc for methods).
  • 🛠️ I have reviewed and tested my code.
  • 🤖 I added or updated automated tests where appropriate.
  • 📄 Documentation updates are included (if applicable).
  • 🔒 I have considered potential security impacts and mitigated risks.
  • 🧰 Dependency updates are listed and explained.

Copy link
Copy Markdown
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a second renderTemplate in the telegram monitor is a non-starter for us.
Please remove this and pull only the escaping into the telgram notification provider instead.

Also, plese share a screenshot of this working (with 100s of notification providers, I cannot do this myself and you have already tested this)

@CommanderStorm CommanderStorm added the pr:please address review comments this PR needs a bit more work to be mergable label Jan 3, 2026
@CommanderStorm CommanderStorm marked this pull request as draft January 3, 2026 15:54
@CommanderStorm CommanderStorm changed the title Fix: escape Telegram MarkdownV2 after template rendering fix: escape Telegram MarkdownV2 after template rendering Jan 3, 2026
@iotux
Copy link
Copy Markdown
Contributor

iotux commented Jan 3, 2026

a second renderTemplate in the telegram monitor is a non-starter for us. Please remove this and pull only the escaping into the telgram notification provider instead.

Also, plese share a screenshot of this working (with 100s of notification providers, I cannot do this myself and you have already tested this)

It looks like double work going on with this:
https://github.com/iotux/uptime-kuma/blob/fix/markdownv2/server/notification-providers/telegram.js

The test template:

*Alarm*
Name: {{ name }}
Status: {{ status }}
Hostname: {{ hostnameOrURL }}
Mon name: {{ monitorJSON.name }}
Mon hostname: {{ monitorJSON.hostName }}
Time: {{ heartbeatJSON.time }}
Message: {{ msg }}

The screenshots:
image

@GivenBY
Copy link
Copy Markdown
Contributor Author

GivenBY commented Jan 4, 2026

@iotux
The issue still reproduces during testing because the default values are injected upstream by NotificationProvider, before the Telegram provider is invoked.

With the latest changes applied, MarkdownV2 escaping now works correctly

Test Template:

*Alarm*
Name: {{ name }}
Status: {{ status }}
Hostname: {{ hostnameOrURL }}
Mon name: {{ monitorJSON.name }}
Mon hostname: {{ monitorJSON.hostName }}
Time: {{ heartbeatJSON.time }}
Message: {{ msg }}

The Screenshots:
image

@GivenBY GivenBY marked this pull request as ready for review January 4, 2026 05:16
@GivenBY GivenBY requested a review from CommanderStorm January 4, 2026 06:32
Copy link
Copy Markdown
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CommanderStorm CommanderStorm added this to the 2.1.0 milestone Jan 4, 2026
@CommanderStorm CommanderStorm merged commit a0a009f into louislam:master Jan 4, 2026
23 checks passed
@CommanderStorm
Copy link
Copy Markdown
Collaborator

Thanks for working on fixing this issue you two ❤️

@GivenBY GivenBY deleted the fix-telegram-markdown-escape branch January 8, 2026 16:48
@CommanderStorm CommanderStorm removed the pr:please address review comments this PR needs a bit more work to be mergable label Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram MarkdownV2 messages should be escaped before sending

3 participants