feat(telegram): accept .html/.htm document uploads and inject stripped text - #36209
feat(telegram): accept .html/.htm document uploads and inject stripped text#36209nitishrajnr wants to merge 1 commit into
Conversation
…d text Previously, .html files sent as Telegram document attachments were rejected with 'Unsupported document type'. This adds .html and .htm to SUPPORTED_DOCUMENT_TYPES and extends the existing text-injection branch (used for .md and .txt) to inline HTML content as plain text into event.text — so the agent receives readable content instead of a path to a cached HTML blob. - Adds .html/.htm → text/html to SUPPORTED_DOCUMENT_TYPES (base.py). - Adds an injection branch in the Telegram adapter that uses BeautifulSoup when available and falls back to a regex+html.unescape tag-strip when it isn't, so no new hard dependency is introduced. - 100 KB injection cap shared with the existing .md/.txt branch. - ImportError-only fallback so genuine parse failures still surface in the catch-all logger.warning. Use case: users sending exported web pages, saved articles, design runbooks or HTML reports get parsed content instead of an unsupported- type error.
|
Related to existing open PRs on the same gap: #12702 (simple |
|
Thanks for addressing HTML document ingestion. Current main has since generalized acceptance and inline injection, but the markup-stripping portion remains distinct. Problems
Suggested changes
Automated hermes-sweeper review. |
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
Two PRs address HTML document ingestion: #36209 adds an allowlist entry plus BeautifulSoup/regex-based Telegram-only text extraction, while #40584 adds the same allowlist support plus a tested Telegram-only sanitizer. Current main already accepts and raw-inlines HTML across Telegram, Discord, and Slack, so only shared markup cleanup remains unresolved.
Related pull requests
- #36209
related— (+24/-0) — keep open for re-scope, not merge-ready as-is: the allowlist/inline-ingestion portion is already on main, and the remaining BeautifulSoup/regex stripping targets the obsoletegateway/platforms/telegram.pypath without regression tests. This follows the visible keep_open review on #36209: port the sanitizer to a shared current-main path and cover all affected adapters. - #40584 [closed]
duplicate— (+80/-1) — closed as superseded in its current form: it duplicates the already-landed HTML acceptance path and implements sanitization only in the obsolete Telegram handler, although its non-content stripping logic and regression tests remain useful reference material. The visible keep_open review proposed salvaging it as shared cross-platform cleanup, but the author subsequently closed it and agreed that any follow-up should use the shared current adapter path with cross-adapter coverage.
Duplicates
#36209 and #40584 substantially duplicate the obsolete HTML/HTM allowlist and Telegram inline-injection changes; #40584 additionally provides a more explicit sanitizer and regression tests.
Suggested consolidation
Use #36209 as the consolidation vehicle, but merge it only after replacing its current diff with shared HTML sanitization for the live Telegram, Discord, and Slack injection paths and adding cross-adapter regression coverage. Keep #40584 closed as superseded/duplicate, while reusing its sanitizer cases and tests as reference for the re-scoped #36209.
Complex graph
flowchart LR
classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
classDef best stroke-width:3px,stroke:#b45309
classDef target stroke-width:3px,stroke:#4338ca
subgraph Dup36209 ["PRs duplicating each other"]
P36209["PR #36209 (open)"]
P40584["PR #40584 (closed)"]
end
class P36209 open
class P40584 closed
class P36209 target
click P36209 "https://github.com/NousResearch/hermes-agent/pull/36209"
click P40584 "https://github.com/NousResearch/hermes-agent/pull/40584"
Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).
Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 8 kB of PR diffs, 4 kB of issue/PR text, 5 kB of discussion (6 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
Problem
.htmlfiles attached as Telegram documents are currently rejected:This blocks a common workflow — sending exported web pages, saved articles, design runbooks, or HTML reports straight into a chat.
Fix
.htmland.htm→text/htmltoSUPPORTED_DOCUMENT_TYPESingateway/platforms/base.py.gateway/platforms/telegram.py(currently only handles.md/.txt) with an HTML→text path:BeautifulSoupwhen available (clean structured strip).html.unescapestrip whenbs4isn't installed — so this does not introduce a new hard dependency.ImportError-only fallback keeps genuine parse failures surfaceable via the outerlogger.warning.Behaviour after the patch
User sends
runbook.html(25 KB) → Hermes injects:…into
event.textexactly like.md/.txttoday. The cached file path is still attached tomedia_urls.Why inline-text injection (not just whitelisting)
Whitelisting alone would cache the file but leave the agent with raw
<div>markup or no content at all. The existing.md/.txtinjection pattern already establishes the precedent.Out of scope
beautifulsoup4topyproject.toml— left out intentionally; the regex fallback is sufficient and avoids dependency churn.Test plan
.htmlfile ≤100 KB from a Telegram chat to a Hermes instance.Verified locally with a 25 KB
.htmlrunbook on a live Hermes profile.