Telegram bot error sending messags with "_"

Telegram bot rejects all messages like this:

Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 43. Args: (510914350, '*Alarm System status*\nAlarm status is armed_home'), kwargs: {'parse_mode': 'Markdown', 'disable_notification': True, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object at 0x70013130>, 'timeout': None}

In order to fix this I changed armed_home to armed home. Is this a known bug or limitation?

Have you tried changing parse mode to html?

not yet, I can live with my str replcae “_” with " "…

If still a concern, I can confirm setting parse_mode to html works but I prefer a utility function like:

    def escape_telegrambot_underscore(self, txt):
        return txt.replace("_", "\\_")

So I can still make other text bold using an asterisk…

1 Like

I’m having exact same issue. Could anyone help on detail how to fix this? I am using data_template in automation.yaml.
Thanks!

Change the parse_mode to html.

I have the same problem,
I don’t find any solution, in StackOverFlow, Telegram Docs, Google yet

Although this issue is quite old, I had the same situation today with my Alarmo integration not sending telegram notifications (worked in test mode but not in live mode).

Then after some fiddling, I got this:

action: notify.telegram_bot
data:
  message: "Yay! A message from Home Assistant."
  data:
    parse_mode: html  

Please do note the second data attribute where I pass the parse_mode. I hope it helps someone.

1 Like