ioBroker.telegram icon indicating copy to clipboard operation
ioBroker.telegram copied to clipboard

Error when using parse mode MarkdownV2

Open Standarduser opened this issue 2 years ago • 1 comments

When using sentTo function for telegram with parse mode MarkdownV2 and texts containing . the message isn't sent. The log file shows following error message:

2022-08-14 12:56:03.782 | error | Cannot send message [chatId - xxxxxxxxx]: Error: ETELEGRAM: 400 Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\'

May it be possible to integrate a check box for auto-escape the following chars?

'_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'

Standarduser avatar Aug 14 '22 11:08 Standarduser

Same issue here, especially with Blocklys that originally used Markdown instead of the newer Markdown_V2. It took me some time to even find and solve it.

A checkbox, as suggested by @Standarduser, will not work in my opinion, because the desired formatting would then also be escaped.

I used a small js function for now:

return text
   .replace(/\_/g, '\\_')
   .replace(/\*/g, '\\*')
   .replace(/\[/g, '\\[')
   .replace(/\]/g, '\\]')
   .replace(/\(/g, '\\(')
   .replace(/\)/g, '\\)')
   .replace(/\~/g, '\\~')
   .replace(/\`/g, '\\`')
   .replace(/\>/g, '\\>')
   .replace(/\#/g, '\\#')
   .replace(/\+/g, '\\+')
   .replace(/\-/g, '\\-')
   .replace(/\=/g, '\\=')
   .replace(/\|/g, '\\|')
   .replace(/\{/g, '\\{')
   .replace(/\}/g, '\\}')
   .replace(/\./g, '\\.')
   .replace(/\!/g, '\\!');

and I wish there was a Blockly tag for that - what do you all mean?

l4rs avatar Sep 21 '22 09:09 l4rs

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.

stale[bot] avatar Dec 21 '22 00:12 stale[bot]

Added escape option: image

image

If someone has a good translation of "escape chars" into german, I will appreciate it. (PR is better)

GermanBluefox avatar Feb 17 '23 08:02 GermanBluefox

"Escapezeichen verwenden" or "Escapezeichen setzen"

Sorry, not able to send a PR at the moment

Standarduser avatar Feb 17 '23 09:02 Standarduser

I would suggest to not escape formatting chars, because that would prevent users to make text italic or bold

Standarduser avatar Feb 17 '23 09:02 Standarduser

I would suggest to not escape formatting chars, because that would prevent users to make text italic or bold

From discussion I understand that in MarkdownV2 required it: https://core.telegram.org/bots/api#markdownv2-style And it is configurable, so the user can prepare text himself as it needed.

GermanBluefox avatar Feb 17 '23 09:02 GermanBluefox

You are right. When I opened this issue I did not notice that escaping all chars would prevent formatting of text. I think * _ ~ | should not be escaped if they appear between char 1 and 126.

Maybe the best solution would be to make it configurable in instance settings?

Standarduser avatar Feb 19 '23 11:02 Standarduser

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.

stale[bot] avatar May 21 '23 11:05 stale[bot]