Conversation
Telegram rejects callback_data longer than 64 bytes with `BUTTON_DATA_INVALID`. The menu plugin adds the menu id plus a 5-byte hash/fingerprint suffix to every `callback_data`, so it is surprisingly easy for a long menu id + a long payload to cross the limit — and the resulting error from Telegram does not reveal which button is at fault. Check each rendered `callback_data` and emit a one-time `console.warn` on the first render that exceeds 64 bytes, naming the menu id, the row/column of the offending button, the actual byte length, and the approximate usable payload size. The warning fires once per menu instance to avoid flooding the console on repeated renders. Per grammyjs#46, this is a warning rather than a hard validation so the plugin does not become brittle if Telegram ever raises the limit. Closes grammyjs#46.
KnorpelSenf
requested changes
Jul 16, 2026
KnorpelSenf
left a comment
Member
There was a problem hiding this comment.
Could you remove the LLM artefacts from the changelog? I don't like to have non-ASCII127 characters in my source files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #46.
Telegram rejects `callback_data` longer than 64 bytes with `BUTTON_DATA_INVALID`, and the menu plugin adds the menu id plus a 5-byte hash/fingerprint suffix to every button's `callback_data`. That combination makes it surprisingly easy for a long menu id + a long payload to cross the limit — and the Telegram error does not identify which button is at fault. Reporters on #46 described spending multiple hours debugging this.
This PR adds a one-time `console.warn` on the first render where any rendered `callback_data` exceeds 64 bytes. The warning includes the menu id, the row/column of the offending button, the actual byte length, and the approximate usable payload size (`~58 - id.length` bytes). Subsequent renders of the same menu instance stay silent so the console is not flooded.
Per the maintainer's direction in the issue thread, this is a warning, not a validation — the plugin does not throw, and will not become brittle if Telegram ever raises the limit.
Test plan
Manual verification: construct a `Menu('x'.repeat(60))` with a `.text({ text: 'hi', payload: 'y'.repeat(20) }, handler)` and render it via `render(ctx)` — the warning fires exactly once.