fix(telegram): expand text_link entities to Markdown in incoming messages - #31075
Open
dskwe wants to merge 2 commits into
Open
fix(telegram): expand text_link entities to Markdown in incoming messages#31075dskwe wants to merge 2 commits into
dskwe wants to merge 2 commits into
Conversation
dskwe
force-pushed
the
fix/telegram-text-link-entities
branch
from
May 23, 2026 18:43
4ae8805 to
dbcb6b8
Compare
1 task
…ages (NousResearch#31071) Telegram text_link entities carry a hidden URL that was silently discarded when building MessageEvent.text. The agent only received the visible text (e.g. '财联社') without the underlying link. Add _expand_text_links() to convert text_link entities into [text](url) Markdown syntax. Handles UTF-16 offset conversion for emoji and supplementary characters. Called for both message text and media captions.
11 tests covering: single/multiple links, CJK text, emoji (UTF-16 surrogate pairs), mixed ASCII+CJK, non-text_link entities, missing URL, empty input, adjacent links, and mid-message links.
dskwe
force-pushed
the
fix/telegram-text-link-entities
branch
from
May 25, 2026 16:12
dbcb6b8 to
433abc4
Compare
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the Telegram entity behavior and accounting for UTF-16 offsets.
Problems
- Current main moved the adapter from
gateway/platforms/telegram.pytoplugins/platforms/telegram/adapter.pyin 5600105, so this patch and itsgateway.platforms.telegramtest import need to be ported. - The current observed-group paths also preserve raw text: text observation builds and persists an unmodified event at
plugins/platforms/telegram/adapter.py:7524-7527and:7331-7354; observed media assigns its raw caption at:7773-7782. The proposed calls only cover normal dispatch, leaving hidden links absent from observed transcript context.
Suggested changes
- Port the helper to the bundled Telegram adapter and normalize entities for normal and observed text/caption ingress.
- Add handler-level coverage for those paths, in addition to the helper cases.
Automated hermes-sweeper review.
| @@ -4816,6 +4870,7 @@ async def _handle_text_message(self, update: Update, context: ContextTypes.DEFAU | |||
| await self._ensure_forum_commands(update.message) | |||
Contributor
There was a problem hiding this comment.
Please ensure the same normalization runs for observed-group text as well. Current main has a separate skipped-message path that builds and persists the event without passing through this dispatched-message branch (plugins/platforms/telegram/adapter.py:7524-7527, :7331-7354), so otherwise hidden URLs remain absent from that agent-visible transcript.
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.
Problem
When a Telegram user sends a rich-text hyperlink (text_link entity), Hermes passes only the visible text to the agent, discarding the underlying URL. The agent cannot access or open the hidden link.
Example: a message visually appears as
财联社linked tohttps://mp.weixin.qq.com/s/..., but the agent only receives the text "财联社".Closes #31071
Root Cause
_handle_text_message()setsevent.text = msg.textdirectly without processing Telegram entities. Thetext_linkentity type carries a.urlattribute that is never inspected. Same issue affects media captions in_handle_media_message().Fix
Add
_expand_text_links()static method that convertstext_linkentities to Markdown[text](url)syntax. Called after building the MessageEvent but before_clean_bot_trigger_text(), for both text messages and media captions.Processes entities in reverse offset order so earlier replacements don't shift subsequent offsets.
Changes
gateway/platforms/telegram.py— add_expand_text_links(), call in_handle_text_message()and media caption handlingtests/gateway/test_telegram_text_links.py— 9 new testsHow to Test