Skip to content

fix(gateway): correctly route and persist Telegram Business inbox messages - #29727

Draft
skiks wants to merge 6 commits into
NousResearch:mainfrom
skiks:pr/telegram-business-inbox
Draft

skiks wants to merge 6 commits into
NousResearch:mainfrom
skiks:pr/telegram-business-inbox

Conversation

@skiks

@skiks skiks commented May 21, 2026

Copy link
Copy Markdown

Summary

  • route Telegram Business inbox traffic passively instead of treating it like a regular interactive chat flow
  • persist Telegram Business inbox payloads and archived text in the life inbox store
  • ignore empty business payload fields and deduplicate business payload probe records
  • add a payload probe script plus regression coverage for business inbox handling

Problem

When Hermes is attached to a Telegram Business account, business inbox messages are not handled like normal Telegram chat traffic. In practice this made business events hard to classify and inspect reliably: payloads could be duplicated, empty fields could leak into storage, and archived business text was not persisted in a form that made debugging or follow-up processing easy.

Scope

This PR intentionally stays focused on Telegram Business inbox detection, persistence, and diagnostics. The higher-level inbox workflow and action-card automation built on top of this layer are kept out of scope for a follow-up branch.

Testing

  • /home/alen/.hermes/hermes-agent/venv/bin/python -m pytest tests/gateway/test_life_inbox_store.py tests/gateway/test_telegram_business_inbox.py tests/gateway/test_telegram_business_payload_probe_script.py -q

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels May 21, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Related to #26654 (Telegram Business delegated inbox support PR) and #26653 (feature request). This PR focuses on inbox detection, persistence, and diagnostics — the higher-level inbox workflow is out of scope per the PR description.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating Business updates from the normal agent path and adding substantial regression coverage.

Problems

  • The implementation and tests target gateway/platforms/telegram.py, but current main moved that adapter to plugins/platforms/telegram/adapter.py in 560010547. The PR test imports the removed module at tests/gateway/test_telegram_business_inbox.py:9, so this needs a plugin-era port rather than a direct application.
  • gateway/life_inbox_store.py:155 introduces HERMES_LIFE_HOME and persists under ~/.hermes-life; this bypasses profile-scoped Hermes state and uses a non-secret env var for behavior. AGENTS.md:102-106 requires behavioral configuration in config.yaml.
  • resolve_life_inbox_db_path() requires a separate accounts.json registry, while scripts/telegram_business_payload_probe.py:26 defaults to a specific Telegram owner ID. That is not a generic Telegram Business setup path.

Suggested changes

  • Port the handlers and tests to plugins/platforms/telegram/adapter.py; current main's plugin handler registration surface from 7c4cde9e8 is the relevant integration point.
  • Rework state/configuration around config.yaml and get_hermes_home(), without user-specific account assumptions.

Automated hermes-sweeper review.

from types import SimpleNamespace

import pytest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gateway.platforms.telegram no longer exists on current main: 560010547 moved the adapter to plugins/platforms/telegram/adapter.py. Port this test and the implementation to the bundled-plugin path rather than restoring the legacy module.

return Path.home() / ".hermes-life"


def resolve_life_inbox_db_path(user_chat_id: str | int, *, life_home: Path | str | None = None) -> Path:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add HERMES_LIFE_HOME as a user-facing behavior setting or place state in ~/.hermes-life. Use a documented config.yaml setting and profile-aware get_hermes_home() storage; otherwise named profiles can silently share or bypass inbox state.

LifeInboxStore,
resolve_life_inbox_db_path,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hard-coded Telegram owner ID makes the shipped probe user-specific. Require an explicit account selection or derive the owner through the configured Business connection instead.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery 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 sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants