Skip to content

Reply keyboard encoding bug #484

@Dooweed

Description

@Dooweed

As far as I understood there is a clever trick being applied to transfer callback data with regular (not inline) buttons. In the aiogram_dialog.utils there is a function encode_reply_callback that encode button id to the button text itself via invisible symbols. It is quite clever solution, but so sad that it is not documented anywhere (at least I couldn't find it).

There is also a bug with this approach - when button text is too long - telegram truncates it, hence we may encounter the case where part of the encoded id is truncated, leading to the button not getting recognized.

The easiest solution will be to add this invisible payload to the beginning of the button instead of the end.

Some more problems with this approach

  • It isn't documented, and some people may end up wondering why buttons are not working (like I did, until I noticed button gets truncated on less characters even though text wasn't changed, but only the id got more characters)
  • To avoid id getting truncated, the user may want to cap button texts on his own, but there isn't much convenient tooling to count how many characters separator and invisible payload will occupy
  • With this approach we're limiting number of charaters can be used in buttons and introduce possibility for unexpected behavior (maybe some clients won't support the characters, or will ignore them), so I'd think about switching to state-based mapping of button text to the id, at least a parameter to choose such one

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions