bostrot / telegram-support-bot

A Telegram ticketing/supporting system.
https://botspace.bostrot.com
GNU General Public License v3.0
451 stars 154 forks source link

Symbols not escaped (Markdown/MarkdownV2) #149

Open Geparder opened 1 year ago

Geparder commented 1 year ago

"Thu May 25 2023 11:16:53 GMT+0000 (Coordinated Universal Time): GrammyError: Call to 'sendMessage' failed! (400: Bad Request: can't parse entities: Character '(' is reserved and must be escaped with the preceding '\')\n" + 2023-05-25T11:16:53.434547877Z ' at toGrammyError (/bot/node_modules/grammy/out/core/error.js:35:12)\n' + 2023-05-25T11:16:53.434553744Z ' at ApiClient.callApi (/bot/node_modules/grammy/out/core/client.js:86:48)'

github-actions[bot] commented 1 year ago

Hello there! As you are a first time Issuer please check whether your issue description is reasonable and complete. If you are having an issue always include the versions you are using (NodeJs, Typescript, ...) as well as a way to reproduce it. Thank you for reading! Now continue :)

gituser commented 1 year ago

ping @bostrot

gituser commented 1 year ago

There is an issue with escaping, e.g. if you try to send this text with MarkdownV2 syntax it will fail:

Test (
'elem1' => 'test123',
'elem2' => 'test345',
'elem3' => 'test444',
)

This is because of the escape rules defined here for urls - https://github.com/bostrot/telegram-support-bot/blob/master/src/middleware.ts#L41

The error in the log will look like this:

GrammyError: Call to 'sendMessage' failed! (400: Bad Request: can't parse entities: Character '=' is reserved and must be escaped with the preceding '\')

Easiest fix is to comment this block of code, but then again for URL markdown won't work.

Also noticed that MarkdownV2 strips all tags like code tags ``` and send to the user as a plaintext message.

Maybe you could take a look at this issue @bostrot.

It seems forwarding messages with MarkDownV2 e.g. with code blocks or using some other elements will not work for your users, guess it's something that should be added as a feature.

Thanks.