fix(telegram): handle channel posts in media handler and thread interim replies - #88903
Open
AdaJyao wants to merge 1 commit into
Open
fix(telegram): handle channel posts in media handler and thread interim replies#88903AdaJyao wants to merge 1 commit into
AdaJyao wants to merge 1 commit into
Conversation
…im replies Two related Telegram fixes for channel (broadcast) chats: 1. _handle_media_message used update.message directly, which is None for channel posts (Telegram delivers those via update.channel_post). Media forwarded into a channel was silently dropped before auth checks. Use _effective_update_message() like the text handler does. 2. Interim assistant commentary (_send_commentary in the stream consumer, and the non-streaming fallback in gateway/run.py) sent without reply_to, so mid-response status messages in channels never carried the reply anchor to the triggering user message. Thread them via initial_reply_to_id / event_message_id.
Collaborator
Related: #51747 already implements the current Telegram adapter channel-media normalization. This PR additionally changes interim reply anchoring, so the overlap is not marked as a duplicate. |
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.
Summary
Two related Telegram fixes for channel (broadcast) chats, found while using a Hermes bot in a Telegram channel:
1. Forwarded media silently dropped in channels
_handle_media_messagecheckedupdate.messagedirectly, which isNonefor channel posts (Telegram delivers those viaupdate.channel_post). Any photo/video/document forwarded into a channel was dropped at the first guard — no log, no event, nothing. The text handler already used_effective_update_message(); the media handler did not.Fix: resolve
msg = self._effective_update_message(update)at the top of_handle_media_message(same as the text/command/location handlers) and use it throughout.2. Interim replies not threaded to the triggering message in channels
Interim assistant messages (commentary between tool calls) were sent via
adapter.send()withoutreply_to:GatewayStreamConsumer._send_commentary()— the streamed pathGatewayRunner._interim_assistant_cb()— the non-streaming fallback pathIn a channel (no
thread_id), the metadata path also produced no reply anchor, so every interim status message appeared as an unthreaded standalone message. The final reply was threaded correctly (via_reply_anchor_for_event), which made the mid-response messages look inconsistent.Fix: pass
reply_to=self._initial_reply_to_idin_send_commentary()andreply_to=event_message_idin the fallbacksend()call.Verification
Live-tested against a real Telegram channel:
update.messagewas None)reply_to=<triggering message id>(verified via send-path debug logging:reply_to='415'etc.)Files changed
gateway/stream_consumer.py— thread_send_commentarysendsgateway/run.py— thread non-streaming interim fallback sendsplugins/platforms/telegram/adapter.py— handle channel posts in_handle_media_message