Skip to content

Keep long linked definitions within Telegram's HTML byte limit - #135

Closed
cloudgpuapp wants to merge 1 commit into
revolter:masterfrom
cloudgpuapp:fix/134-linked-definition-budget
Closed

cloudgpuapp wants to merge 1 commit into
revolter:masterfrom
cloudgpuapp:fix/134-linked-definition-budget

Conversation

@cloudgpuapp

Copy link
Copy Markdown

Fixes #134. Adding one link per word can make the rendered HTML larger than Telegram's parser accepts, even when the visible definition fits. The Bot API checks the UTF-8 byte size before parsing entities in Client.cpp.

Link mode now reserves room for the header, ellipsis, attribution and suffix, then stops at a complete word or punctuation fragment before crossing that byte limit. Plain mode and short linked definitions are unchanged.

Two offline regressions passed. The original produced 42,590 bytes on the synthetic long Romanian definition. The patched renderer keeps the payload below the parser limit, leaves valid links and keeps the footer. No live Telegram bot was contacted.

AI assistance: OpenAI Codex assisted with the patch and tests.

revolter commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Hi, and thank you so much for looking into this and for the detailed explanation, especially the pointer to where the Bot API checks the byte size. That's really useful.

I'm going to close this one, though, because I'd like to fix #134 myself. I'm in the middle of a bigger modernization of the bot and I'm keeping the commits and wording consistent with my own style. Unit tests are also planned for a later step (#142), so I'd rather not add a test setup in a separate PR yet.

Your write-up will definitely help when I get to it. Thanks again!


Generated by Claude Code

@revolter revolter closed this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix links missing on long definitions

2 participants