Skip to content

feat(telegram/plugin): port guest mode + buffer fixes to adapter.py - #49801

Closed
elphamale wants to merge 3 commits into
NousResearch:mainfrom
elphamale:fix/telegram-guest-mode-adapter
Closed

feat(telegram/plugin): port guest mode + buffer fixes to adapter.py#49801
elphamale wants to merge 3 commits into
NousResearch:mainfrom
elphamale:fix/telegram-guest-mode-adapter

Conversation

@elphamale

Copy link
Copy Markdown

Upstream commit 5600105 moved gateway/platforms/telegram.pyplugins/platforms/telegram/adapter.py as part of the plugin system migration. PRs #43049, #49116, and #49186 all targeted the old path and now conflict.

This PR is the consolidated replacement, applying the same changes to the new file:

Changes

From #43049 (guest mode delivery)

  • State vars: _pending_guest_queries, _guest_only_chats, _guest_reply_buffer in __init__
  • send() buffer block: routes guest-chat calls to the reply buffer instead of rejected sendMessage
  • TypeHandler registration for guest_message updates (Bot API 10.0 raw field)
  • _handle_guest_message_update() handler — parses payload, stores guest_query_id, routes through normal pipeline
  • on_processing_complete() flush — fires answerGuestQuery with the buffered response
  • Media-method guards (send_voice, send_image_file, send_document, send_video, send_image) return a descriptive error for guest chats where the bot can't upload files

From #49116 (sender_chat identity)

  • _build_message_event(): when from_user is None (user posting as a channel), fall back to sender_chat.id / sender_chat.title for user identity so auth checks match and session keys are stable

From #49186 (buffer quality)

  • Drop tool-progress blocks from the guest buffer (expect_edits/notify metadata flag detection)
  • Strip the streaming cursor before buffering
  • startswith-accumulation: cumulative streaming updates replace the buffer; overflow chunks append

Supersedes #43049, #49116, #49186.

Upstream commit 5600105 moved gateway/platforms/telegram.py →
plugins/platforms/telegram/adapter.py.  This applies the equivalent
of PRs NousResearch#43049 / NousResearch#49116 / NousResearch#49186 to the new path:

- NousResearch#43049 (guest mode): _pending_guest_queries / _guest_only_chats /
  _guest_reply_buffer state; send() buffer block; TypeHandler
  registration; _handle_guest_message_update(); on_processing_complete()
  answerGuestQuery flush; media-method guards for send_voice /
  send_image_file / send_document / send_video / send_image.

- NousResearch#49116 (sender_chat): _build_message_event() uses sender_chat.id /
  .title when from_user is None (channel-as-user posts in groups).

- NousResearch#49186 (buffer quality): tool-progress drops (expect_edits/notify
  flags), cursor-strip before buffering, startswith-accumulation so
  cumulative streaming frames replace rather than double-append.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@elphamale
elphamale force-pushed the fix/telegram-guest-mode-adapter branch from 9687e65 to f7dfd57 Compare June 20, 2026 21:00
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter labels Jun 20, 2026
elphamale and others added 2 commits June 21, 2026 00:04
PTB 22.6's Update.ALL_TYPES does not include guest_message (Bot API
10.0 field not yet in the typed layer). Telegram only delivers an
update type if it is listed in allowed_updates — without this,
getUpdates never returns guest_message payloads and guest mode is
silently dead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The _reconnect_polling path had a different indentation for its
allowed_updates call so the previous replace_all missed it. This
ensures guest_message is requested even after a network-error reconnect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@elphamale

Copy link
Copy Markdown
Author

Closing as superseded by #56476/#56477.

This PR was a mechanical port of #43049/#49116/#49186's logic from the old gateway/platforms/telegram.py into plugins/platforms/telegram/adapter.py. All three of those are now closed as superseded by the same rebuild, so this port is superseded wholesale along with them.

@elphamale elphamale closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants