Skip to content

feat(telegram): auto-detect HTML tags and use parse_mode=HTML in send_message#1709

Merged
teknium1 merged 2 commits intomainfrom
hermes/hermes-c91521bf
Mar 17, 2026
Merged

feat(telegram): auto-detect HTML tags and use parse_mode=HTML in send_message#1709
teknium1 merged 2 commits intomainfrom
hermes/hermes-c91521bf

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Auto-detects HTML tags in Telegram messages sent via send_message and uses parse_mode='HTML' instead of MarkdownV2 conversion. Enables cron jobs and agents to send rich HTML-formatted Telegram messages.

Reimplements the concept from PR #1568 by @ashaney against the current codebase, which now has a full MarkdownV2 formatting pipeline.

Changes

tools/send_message_tool.py:

  • Before the MarkdownV2 formatting pipeline, check if the message contains HTML tags via regex: re.search(r'<[a-zA-Z/][^>]*>', message)
  • If HTML detected: skip MarkdownV2 conversion, send with parse_mode='HTML'
  • If no HTML: use existing MarkdownV2 pipeline (unchanged behavior)
  • HTML parse failures fall back to plain text, matching existing MarkdownV2 error handling

tests/tools/test_send_message_tool.py:

  • Updated telegram mock to include ParseMode.HTML
  • 6 new tests: HTML detection, plain text MarkdownV2 path, code/pre tags, closing tags, math angle brackets (no false positive), HTML parse failure fallback

Credit

Inspired by @ashaney's PR #1568, which identified this gap. The regex is theirs.

Add the ability to selectively enable/disable individual MCP server
tools through the interactive 'hermes tools' TUI.

Changes:
- tools/mcp_tool.py: Add probe_mcp_server_tools() — lightweight function
  that temporarily connects to configured MCP servers, discovers their
  tools (names + descriptions), and disconnects. No registry side effects.

- hermes_cli/tools_config.py: Add 'Configure MCP tools' option to the
  interactive menu. When selected:
  1. Probes all enabled MCP servers for their available tools
  2. Shows a per-server curses checklist with tool descriptions
  3. Pre-selects tools based on existing include/exclude config
  4. Writes changes back as tools.exclude entries in config.yaml
  5. Reports which servers failed to connect

The existing CLI commands (hermes tools enable/disable server:tool)
continue to work unchanged. This adds the interactive TUI counterpart
so users can browse and toggle MCP tools visually.

Tests: 22 new tests covering probe function edge cases and interactive
flow (pre-selection, exclude/include modes, description truncation,
multi-server handling, error paths).
…_message

When _send_telegram detects HTML tags in the message body, it now sends
with parse_mode='HTML' instead of converting to MarkdownV2. This allows
cron jobs and agents to send rich HTML-formatted Telegram messages with
bold, italic, code blocks, etc. that render correctly.

Detection uses the same regex from PR #1568 by @ashaney:
  re.search(r'<[a-zA-Z/][^>]*>', message)

Plain-text and markdown messages continue through the existing
MarkdownV2 pipeline. The HTML fallback path also catches HTML parse
errors and falls back to plain text, matching the existing MarkdownV2
error handling.

Inspired by: github.com/ashaney — PR #1568
@teknium1 teknium1 merged commit b16186a into main Mar 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant