Skip to content

feat(telegram): add plugin-owned callback actions - #65255

Open
prvk wants to merge 2 commits into
NousResearch:mainfrom
prvk:feat/platform-callback-hooks
Open

feat(telegram): add plugin-owned callback actions#65255
prvk wants to merge 2 commits into
NousResearch:mainfrom
prvk:feat/platform-callback-hooks

Conversation

@prvk

@prvk prvk commented Jul 15, 2026

Copy link
Copy Markdown

Summary

  • adds a platform_callback plugin hook for authorized Telegram callbacks that are not claimed by built-in handlers
  • lets cron jobs attach bounded inline keyboards through repeatable --button options
  • carries keyboards through live gateway and standalone Telegram delivery

Safety

  • transport objects stay inside the Telegram adapter; plugins receive normalized scalar context
  • existing Telegram callback authorization runs before plugin dispatch
  • callback answers and replacement keyboards are strictly bounded
  • existing jobs and sends remain byte-compatible when no buttons are configured

Verification

  • 357 focused gateway, cron, CLI, and standalone-send tests pass
  • Ruff checks pass for all changed files

@alt-glitch alt-glitch added type/feature New feature or request comp/cron Cron scheduler and job management comp/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins comp/tools Tool registry, model_tools, toolsets platform/telegram Telegram bot adapter P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #21469 / #21471: this PR adds a post-built-in callback hook plus cron-delivery buttons, while #21471's pre-callback hook intercepts before built-in routing. Same extension area, different ownership semantics; maintainers can evaluate them together.

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

Thanks for the focused post-built-in callback design and for covering both live and standalone delivery paths.

Problems

  • tools/send_message_tool.py:1353 attaches markup only when the media item is the final input entry. If that entry is missing or fails after an earlier media send succeeds, delivery succeeds without any keyboard.
  • cron/jobs.py:1053 accepts built-in callback prefixes. Telegram claims mp:, gt:, ea:, sc:, cl:, and update_prompt: before the new hook (plugins/platforms/telegram/adapter.py:5637-5945 on current main), so those buttons are not plugin-owned.
  • --button has no supported clear operation despite cron edit advertising replacement; an empty button list is invalid.
  • The public hook reference still says only two hook return values affect behavior (website/docs/user-guide/features/hooks.md:374).

Suggested changes

  • Deliver markup on the final successful message/media and test missing-final-media behavior.
  • Reserve or reject built-in callback namespaces, add a clear-buttons path, and document the new hook contract.

Automated hermes-sweeper review.

media_kwargs["caption"] = _tg_caption
media_kwargs["parse_mode"] = send_parse_mode
if (
reply_markup is not None

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.

This selects the final input attachment rather than the final successfully delivered attachment. If this final file is absent (or its send fails) after an earlier media send succeeds, the method returns success but no message has reply_markup. Attach the keyboard to the final successful send and cover that fallback.

Comment thread cron/jobs.py
label, callback_data = (part.strip() for part in raw.split("=", 1))
if not label or len(label) > 64:
raise ValueError("button labels must contain 1 to 64 characters")
if not callback_data or len(callback_data.encode("utf-8")) > 64:

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.

Please reject or reserve Telegram's built-in callback namespaces here. Values such as ea:, sc:, cl:, gt:, mp:, and update_prompt: are consumed before the post-built-in plugin hook, contradicting the CLI contract that this callback data is handled by platform_callback.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 16, 2026
@acherley

acherley commented Aug 1, 2026

Copy link
Copy Markdown

Thanks — this overlaps a generic callback/delivery surface I was preparing for an external plugin, so I’m avoiding a competing PR while this and #59159 are open.

A concrete external-plugin consumer needs the following combination:

  1. Claim only its own callback-data prefix, while preserving built-in callback families and normal fallback behavior.
  2. Attach an inline keyboard to a photo delivery (a human-in-the-loop prompt may be image-first rather than text-first).
  3. Receive a bounded post-send hook so it can bind the returned Telegram message ID and later remove stale markup.
  4. Preprocess a per-target cron delivery before media extraction without being able to override core-owned route metadata (job_id, thread_id, or direct_messages_topic_id).

Does the proposed cron button syntax remain attached when the result is primarily a MEDIA: image, and is a platform plugin expected to claim callbacks through platform_callback or through the PTB-handler registration proposed in #59159?

I’m happy to adapt the external consumer to whichever single API maintainers prefer; the goal is to converge rather than add another overlapping callback hook.

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

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management comp/plugins Plugin system and bundled plugins comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants