Skip to content

fix(telegram): handle channel post updates#25327

Closed
brndnsvr wants to merge 2 commits into
NousResearch:mainfrom
brndnsvr:fix/telegram-channel-posts
Closed

fix(telegram): handle channel post updates#25327
brndnsvr wants to merge 2 commits into
NousResearch:mainfrom
brndnsvr:fix/telegram-channel-posts

Conversation

@brndnsvr

Copy link
Copy Markdown
Contributor

Summary

  • Route Telegram handlers through effective_message so channel_post updates build gateway events instead of being ignored
  • Preserve channel identity for channel posts without from_user so operators can allowlist numeric channel IDs
  • Normalize Telegram chat type detection for enum and mock/plain-string values

Test Plan

  • /Users/bss/.hermes/hermes-agent/venv/bin/python -m py_compile gateway/platforms/telegram.py
  • /Users/bss/.hermes/hermes-agent/venv/bin/python -m pytest tests/gateway/test_telegram_documents.py tests/gateway/test_telegram_conflict.py tests/gateway/test_home_target_env_var.py tests/gateway/test_telegram_channel_posts.py -q -o 'addopts='

Copilot AI review requested due to automatic review settings May 14, 2026 00:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Telegram regression coverage and adapter changes to correctly process channel broadcast updates (Update.channel_post) by using effective_message and preserving a usable identity when from_user is missing.

Changes:

  • Added regression tests for Telegram channel_post handling and channel identity mapping.
  • Updated Telegram handlers to consume effective_message (so channel posts are not dropped).
  • Normalized Telegram chat type parsing and mapped channel posts without from_user to use channel identity.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tests/gateway/test_telegram_channel_posts.py New regression tests for channel posts and identity behavior.
gateway/platforms/telegram.py Use effective_message in handlers; normalize chat type; set channel identity fallback when from_user is absent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/gateway/test_telegram_channel_posts.py Outdated
Comment thread tests/gateway/test_telegram_channel_posts.py Outdated
Comment thread gateway/platforms/telegram.py
Comment thread gateway/platforms/telegram.py Outdated
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing approach with existing open PR #9500, both addressing issue #3634 (Telegram channel_post updates silently dropped). This PR takes a different approach using effective_message and also adds chat type normalization.

@brndnsvr

Copy link
Copy Markdown
Contributor Author

Thanks for flagging. I looked at #9500 and agree they overlap on #3634, but this PR is intentionally a bit broader:

  • fix: handle Telegram channel-post commands #9500 is scoped to channel-post slash commands and adds a channel-post command handler/helper.
  • This PR fixes the shared handler assumption by reading update.effective_message, so the same path covers normal messages and channel posts for text, commands, locations, and media handlers that PTB dispatches to those filters.
  • It also fixes channel-post identity when from_user is absent, so channel allowlisting/session attribution can use the numeric channel ID instead of ending up with a missing user identity.
  • It includes chat type normalization because the channel fallback depends on reliably recognizing ChatType.CHANNEL across real PTB enum values and test/plain-string values.

I also checked current python-telegram-bot filter behavior locally: filters.TEXT and filters.COMMAND both match a synthetic Update.channel_post, so the main drop appears to be handlers reading update.message instead of effective_message, not missing registration for the current PTB version. If maintainers prefer the more explicit filters.UpdateType.CHANNEL_POSTS & ... registration style from #9500 for readability/defense-in-depth, I can fold that in too, but I avoided adding duplicate handlers since the existing filters already match channel posts.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #28531. Authorship preserved (rebase-merge). #28531

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 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.

4 participants