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:
🔮 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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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!
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!