Skip to content

feat(telegram): support custom base_url for credential proxy routing - #6851

Closed
handsdiff wants to merge 1 commit into
NousResearch:mainfrom
handsdiff:telegram-base-url-upstream
Closed

handsdiff wants to merge 1 commit into
NousResearch:mainfrom
handsdiff:telegram-base-url-upstream

Conversation

@handsdiff

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for custom base_url and base_file_url in the Telegram platform config via extra dict. When set, all Telegram Bot API requests and file downloads are routed through the custom URL instead of api.telegram.org.

This enables credential proxy architectures where the bot token should never touch the agent VM — the agent uses a proxy credential as its token, and a reverse proxy injects the real bot token before forwarding to Telegram's API.

Related Issue

No existing issue. This enables a new deployment pattern for hosted/multi-tenant Hermes installations.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • gateway/platforms/telegram.py — 10 lines added after Application.builder().token() (line 515)
    • Reads extra.base_url and extra.base_file_url from platform config
    • Passes to ApplicationBuilder.base_url() / .base_file_url()
    • Uses the existing BaseUrl type support in python-telegram-bot (string concatenation: base_url + token)

How to Test

  1. Set up a reverse proxy that rewrites /telegram/{proxy_token}/{method}https://api.telegram.org/bot{real_token}/{method}
  2. Configure Telegram platform in config.yaml:
    platforms:
      telegram:
        enabled: true
        token: "proxy-credential-here"
        extra:
          base_url: "https://your-proxy.example.com/telegram/"
          base_file_url: "https://your-proxy.example.com/telegram-file/"
  3. Start the gateway — Telegram should connect via the proxy URL
  4. Send a message to the bot — verify it responds through the proxy

Without extra.base_url set, behavior is unchanged (uses default api.telegram.org).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu 24.04 (exe.dev VM)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

When extra.base_url is set in the Telegram platform config, use it as
the base URL for all Telegram API requests instead of api.telegram.org.
This allows agents to route Telegram traffic through the credential
proxy, which injects the real bot token — the VM never sees it.

Also supports extra.base_file_url for file downloads (defaults to
base_url if not set separately).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@teknium1

Copy link
Copy Markdown
Collaborator

Merged via PR #7154. Your commit was cherry-picked with authorship preserved. Clean feature — thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants