Skip to content

fix: use rich Telegram messages for standalone sends - #46952

Open
DazyPanda wants to merge 1 commit into
NousResearch:mainfrom
DazyPanda:fix/telegram-standalone-rich-send
Open

fix: use rich Telegram messages for standalone sends#46952
DazyPanda wants to merge 1 commit into
NousResearch:mainfrom
DazyPanda:fix/telegram-standalone-rich-send

Conversation

@DazyPanda

Copy link
Copy Markdown

Summary

  • route standalone Telegram sends through sendRichMessage when available
  • keep HTML messages on the legacy HTML path and preserve MarkdownV2/plain fallback for rich parser/capability failures
  • avoid fallback resend on transient rich-send failures to reduce duplicate-message risk
  • use Telegram rich-message length limits before chunking when rich sends are enabled

Tests

  • python -m pytest tests/tools/test_send_message_tool.py tests/hermes_cli/test_send_cmd.py tests/gateway/test_telegram_rich_messages.py -q

@alt-glitch alt-glitch added type/feature New feature or request comp/tools Tool registry, model_tools, toolsets platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #46118 — both add a Telegram sendRichMessage fast-path to _send_telegram in tools/send_message_tool.py (same approach, same file). #46118 is the earliest open PR for this feature (implements #45854); this one adds extra transient-failure fallback guarding (no legacy resend on timeout/network errors to avoid duplicate messages). Related: #46263 (duhman's opt-in standalone-tool variant). Maintainers may want to fold the transient-failure handling here into the canonical #46118.

@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—the current-main gap is real: standalone Telegram sends still format content and call legacy bot.send_message (tools/send_message_tool.py:1136-1144, 1242-1246), while the gateway has a richer delivery path.

Problems

  • tools/send_message_tool.py:806 defaults rich delivery on and evaluates raw values with bool(). That conflicts with the documented/default opt-in at hermes_cli/config.py:2505; notably, bool("false") is true while the gateway treats that value as an opt-out (plugins/platforms/telegram/adapter.py:1272-1283).
  • tools/send_message_tool.py:1125 bypasses the gateway's rich eligibility and client-safety guards (plugins/platforms/telegram/adapter.py:1452-1461), and :1128 omits its newline normalization (:1506-1521).
  • tools/send_message_tool.py:1149 references the pre-plugin gateway.platforms.telegram module, absent from current production paths. The fallback would consequently skip legacy chunking after a rich rejection.

Suggested changes

  • Salvage this against the current sender, preserving the later UTF-16 chunking and media-caption work (b7c4369, 709da84).
  • Share the gateway's opt-in coercion, eligibility, safe payload construction, and fallback behavior; add standalone regression coverage for these paths.

Automated hermes-sweeper review.


# Platform message length limits (from adapter class attributes for
# built-in platforms; from PlatformEntry.max_message_length for plugins).
telegram_rich_enabled = bool(

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.

Rich messages are opt-in on current main (hermes_cli/config.py:2505), but this defaults a missing value to True; additionally bool("false") is true. Please use the gateway's false-by-default string-aware coercion and add standalone opt-out regressions.

@@ -1047,48 +1124,80 @@ async def _send_telegram(token, chat_id, message, media_files=None, thread_id=No
warnings = []

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 enables rich sends for every plain message, bypassing the gateway's construct eligibility and safety exclusions for details-plus-math and CJK-rich content (plugins/platforms/telegram/adapter.py:1452-1461). The standalone path needs to share that policy before attempting the raw endpoint.

return _error(f"Telegram rich send failed: {rich_error}")

if last_msg is None:
try:

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.

Current main migrated the Telegram adapter to plugins.platforms.telegram.adapter; gateway.platforms.telegram is not a tracked production module. This import will fail during rich fallback, leaving the whole formatted payload unchunked. Use the plugin path and preserve current post-format UTF-16 chunking.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages 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 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists 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 type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants