Skip to content

fix(telegram): use effective_message in _handle_media_message for channel posts (#52126) - #52131

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-channel-media-attachments
Closed

fix(telegram): use effective_message in _handle_media_message for channel posts (#52126)#52131
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-channel-media-attachments

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes silent dropping of file attachments (documents, PDFs, images, voice, etc.) sent to Telegram channels. The _handle_media_message handler used update.message directly, which is None for channel broadcasts (PTB puts them in update.channel_post). Switches to _effective_update_message() — the same pattern already used by _handle_text_message and _handle_command.

Related Issue

Fixes #52126

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • plugins/platforms/telegram/adapter.py: Replace update.message references in _handle_media_message() with msg = self._effective_update_message(update) so channel-post media (documents, photos, voice, audio, video, stickers) is properly downloaded and cached.
  • tests/gateway/test_telegram_channel_posts.py: Add regression test test_media_handler_processes_channel_post_document verifying channel-post documents are processed, not silently dropped.
  • tests/gateway/test_telegram_documents.py: Update _make_update() fixture to set update.effective_message = msg so existing document tests work with the _effective_update_message() code path.

How to Test

  1. Create a Telegram channel (not supergroup), add the bot as admin with Privacy Mode OFF
  2. Configure free_response_chats and allowed_chats in config.yaml to include the channel
  3. Send a file/document to the channel
  4. Before fix: gateway logs show no "Cached user document" entry, file is silently dropped
  5. After fix: file is cached and delivered to the agent normally
  6. Run pytest tests/gateway/test_telegram_channel_posts.py tests/gateway/test_telegram_documents.py -q — all tests pass

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: plugins/platforms/telegram/adapter.py:_handle_media_message (callers: 1, flows: media message dispatch)
  • Blast radius: LOW — single function, same pattern as 3 sibling handlers
  • Related patterns: _handle_text_message and _handle_command already use _effective_update_message() for the same channel-post routing

…nnel posts

Telegram channel broadcasts deliver messages via update.channel_post,
not update.message. The _handle_media_message handler used update.message
directly, causing all channel file attachments to be silently dropped.

Use _effective_update_message() (the same pattern used by _handle_text_message
and _handle_command) so channel-post documents, photos, voice, and other media
are properly downloaded and cached.

Fixes NousResearch#52126
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #51747, which applies the identical _effective_update_message() fix to _handle_media_message in the current plugins/platforms/telegram/adapter.py and was opened earlier. The older competing PRs (#28614, #28813, #35720) implement the same fix against the pre-relocation gateway/platforms/telegram.py path that no longer exists on main — related, but not the implementable version. Maintainer to pick between this and #51747.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #51747, which applies the identical _effective_update_message() fix to _handle_media_message and was opened ~13 hours earlier.

Both PRs solve the same root cause: channel-post media attachments (documents, photos) are silently dropped because update.message is None for channel broadcasts. #51747's diff is slightly more comprehensive (141 vs 127 lines) with a helper function for channel photo messages.

Superseded by #51747.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Telegram channel file attachments silently dropped in _handle_media_message

2 participants