fix(telegram): cache channel-post media via effective_message (#51543) - #51747
fix(telegram): cache channel-post media via effective_message (#51543)#51747michaelversluis wants to merge 1 commit into
Conversation
Related: this is the same Key difference for the maintainer: the Telegram adapter was relocated during the plugin refactor. The three earlier open PRs target the old path |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting the current plugin adapter and adding a focused channel-post media regression. The reported early return still exists on current main at plugins/platforms/telegram/adapter.py:7764.
Problems
- Current main added the intake authorization prefilter in commit
c648ecdcaafter this PR's base. A salvage must also replace the laterupdate.messagereferences in the auth block atplugins/platforms/telegram/adapter.py:7766-7770with the resolvedmsg. Otherwise channel posts passNoneinto_is_user_authorized_from_message(); that helper derives a channel identity frommessage.sender_chat(adapter.py:769-827), so authorization would not inspect the actual broadcast sender.
Suggested changes
- Resolve
msgbefore every media gate and use it for authorization, logging, group observation, and processing. - Add a channel-post media test with a non-allowlisted
sender_chatthat asserts no cache/enqueue occurs, alongside the positive caching test.
Automated hermes-sweeper review.
| # matching ``_handle_text_message`` (which was already fixed). Guarding on | ||
| # ``update.message`` alone silently dropped every channel-post attachment. | ||
| msg = self._effective_update_message(update) | ||
| if not msg: |
There was a problem hiding this comment.
When salvaging this against current main, also pass msg to the authorization prefilter added by c648ecdca after this PR's base. Leaving that call on update.message gives channel posts None, so the prefilter cannot authorize their sender_chat identity.
0537809 to
c4fd410
Compare
|
Rebased onto current main (6997dc8) and addressed the sweeper findings:
PR is mergeable again. |
|
@teknium1 good like this? |
…search#51543) Telegram delivers channel broadcasts as `update.channel_post`, not `update.message`. `_handle_media_message` guarded on `update.message` alone and bailed immediately for channel posts, so file/photo/video/voice attachments to a broadcast channel were silently dropped — only the caption text reached the agent and nothing was cached. `_handle_text_message` and `_handle_command` already resolve the payload via `_effective_update_message(update)` (effective_message → message → None); the media handler was missed during the plugin refactor that deleted the old `gateway/platforms/telegram.py` (commit 5600105). - Resolve the message via `_effective_update_message` and replace the five `update.message` references in the early-return block with the resolved `msg`, mirroring the text/command handlers. - Add a regression test asserting a channel-post photo is routed into the caching pipeline (RED before the fix: the handler returns early and never enqueues the photo). - Update `_make_update` in test_telegram_documents.py to expose `effective_message`, matching real python-telegram-bot Update objects. Fixes NousResearch#51543
c4fd410 to
b53228e
Compare
|
Rebased onto current |
Fixes #51543
Problem
Telegram delivers channel broadcasts as
update.channel_post, notupdate.message._handle_media_messageguarded onif not update.message:and bailed immediately for channel posts, so file / photo / video / voice attachments sent to a broadcast channel were silently dropped — only the caption text reached the agent and nothing was cached at~/.hermes/cache/.The sibling handlers
_handle_text_messageand_handle_commandalready resolve the payload via_effective_update_message(update)(which returnseffective_message → message → None). The media handler was missed during the plugin refactor that deleted the oldgateway/platforms/telegram.py(commit560010547); this ports the same fix to the new plugin location.Fix
_effective_update_message(update)and replace the fiveupdate.messagereferences in the early-return block with the resolvedmsg, mirroring the text/command handlers. The rest of the method already used a localmsg.Tests
test_media_handler_uses_effective_message_for_channel_postintests/gateway/test_telegram_channel_posts.py: sends a channel-post photo and asserts it is routed into the caching pipeline. Verified RED on the unpatched handler (the earlyreturnmeans_enqueue_photo_eventis never called) and GREEN after the fix._make_updateintests/gateway/test_telegram_documents.pyto exposeeffective_messagealongsidemessage, matching real python-telegram-botUpdateobjects (whereeffective_messagealways resolves the active payload). Without this the existing mock only modelled.message.test_telegram_channel_posts.py,test_telegram_documents.py,test_telegram_group_gating.py→ 90 passed.NL — kort voor de eigen administratie: kanaal-broadcasts kwamen binnen als
channel_posti.p.v.message, waardoor de media-handler meteen afhaakte en bijlagen in kanalen nooit werden gecached. Dezelfdeeffective_message-resolutie die de tekst- en command-handlers al gebruiken nu ook in de media-handler gezet, met een regressietest die zonder de fix faalt.