question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML is always escaped for Telegram

See original GitHub issue

📣 Notification Service(s) Impacted Telegram

🪲 Describe the bug HTML is always escaped even if format=html is passed, so it’s not possible send a notification with any HTML formatting. Currently I switched to Markdown as a workaround, but I’d have to escape a lot of symbols to make it work correctly. I think the data should be passed as-is if html format is specified.

💡 Screenshots and Logs I have apprise-api in Docker with APPRISE_STATELESS_URLS: tgram://${TELEGRAM_LOGGER_TOKEN}/${TELEGRAM_LOGGER_CHATID}/?format=html and testing with curl -X POST -d '{"body":"<b>not bold</b>"}' -H "Content-Type: application/json" http://localhost:8000/notify Result: image

🔮 Additional context Looking at NotifyTelegram.py I think

                # HTML
                title = NotifyTelegram.escape_html(title, whitespace=False)

            # HTML
            body = NotifyTelegram.escape_html(body, whitespace=False)

        if title and self.notify_format == NotifyFormat.TEXT:
            # Text HTML Formatting
            payload['text'] = '<b>%s</b>\r\n%s' % (
                title,
                body,
            )

should be changed to

            # HTML
            if self.notify_format == NotifyFormat.TEXT:
                body = NotifyTelegram.escape_html(body, whitespace=False)

        if title and self.notify_format == NotifyFormat.TEXT:
            # Text HTML Formatting
            title = NotifyTelegram.escape_html(title, whitespace=False)
            payload['text'] = '<b>%s</b>\r\n%s' % (
                title,
                body,
            )

but I’m not a python developer so I won’t risk changing it myself 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zzenegcommented, Feb 10, 2020

Thanks for the idea, I ended up with forking and changing your Docker image. I’ll use it until the official one is updated. Everything looks good, I’m able to send HTML to Telegram. Thanks!

0reactions
caronccommented, Feb 10, 2020

Glad you figured it all out! 🙂

I’m going to close off this ticket now then. But if you do have any more issues, please don’t hesitate to open up another!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Telegram HTML messages should be htlm-escaped ... - GitHub
Describe the bug. Matterbridge does not sanitize (escape, encode) relayed messages when HTML mode is activated for Telegram.
Read more >
Telegram does not escape some markdown characters
sounds like Telegram doesn't support escape characters for markdown, so i suggest you to use HTML instead: <b>test*test</b>.
Read more >
telegram-format - npm
Text which should be escaped so it does not interfer with formatting. User generated Text should always be escapted to prevent errors. Keywords....
Read more >
HTML escape characters | Example code - EyeHunts
These are three main characters which should be always escaped in your HTML ... HTML example code escape and unescape char using JavaScript....
Read more >
Telegram Bot API - How to format messages - AutoHotkey
Also, escaping certain characters in the right way seems crucial. To do that, you'll have to arrange with both Telegram's and AHK's escape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found