GochoMugo / tgfancy

A Fancy, Higher-Level Wrapper for Telegram Bot API
MIT License
184 stars 16 forks source link

Text paging cutting markdown tags #17

Open dustyhorizon opened 6 years ago

dustyhorizon commented 6 years ago

Hello,

I have a specific use case where I will send text reports as messages over telegram and would contain several markdown tags. However, there are cases where text paging cuts in between these tags, causing telegram to error with Can't find end of the entity starting at byte offset xxxx.

Any advice?

kamikazechaser commented 6 years ago

The library currently paginates the first 4088 characters if the entire text > 4096 characters. The main issue is that if the markdown closing tag ends up somewhere > 4096'th character, it will definitely break the markdown with or without the library. The only solution seems to allow users to pass in their own reserve space value. A higher reserve space value means a lower probability of the markdown breaking, however it still does not guarantee there will be no breakage since its entirely dependent on the position of the tags. So its all about where the tag will fall.

dustyhorizon commented 6 years ago

Do you think it is possible to parse the response after text paging for any broken markdown if parsed by Telegram and to 'append/prepend' the necessary tags to both pages so that the message gets through instead of being rejected by the server?

An alternative would be to push the last markdown tagged text to from the first message to the second message so that it doesn't get 'cut'.

Both way seems pretty complicated to implement though, not very sure.