Skip to content

feat(telegram): add webhook mode as alternative to polling#3880

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-76df6a95
Mar 30, 2026
Merged

feat(telegram): add webhook mode as alternative to polling#3880
teknium1 merged 1 commit intomainfrom
hermes/hermes-76df6a95

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Adds optional webhook mode to the Telegram adapter. Salvaged from PR #2022 by SHL0MS.

Motivation

Cloud platforms (Fly.io, Railway) auto-wake suspended machines on inbound HTTP, but not on outbound connections. Long polling is outbound, so the machine can never sleep. Webhook mode flips the direction — Telegram pushes updates to the bot's URL, enabling cost-efficient sleep-when-idle deployments.

Usage

# Add to ~/.hermes/.env
TELEGRAM_WEBHOOK_URL=https://my-app.fly.dev/telegram
TELEGRAM_WEBHOOK_PORT=8443        # optional, default 8443
TELEGRAM_WEBHOOK_SECRET=mysecret  # optional, recommended

Behavior

  • Default (no env var): polling mode, identical to current behavior
  • With TELEGRAM_WEBHOOK_URL: starts HTTP webhook server via python-telegram-bot's start_webhook()
  • Disconnect handles both modes (updater.stop() works for both)
  • All existing features preserved: network error recovery, polling conflict detection, DM topics setup

Integration notes

  • Uses python-telegram-bot's built-in start_webhook() — no new dependencies
  • Webhook secret token support for verifying updates come from Telegram
  • URL path auto-extracted from webhook URL
  • Polling error callbacks only registered in polling mode (not applicable to webhooks)

Verification

  • 199 Telegram tests pass, 0 failures
  • Compiles clean

Closes #2022. Credit to SHL0MS for the feature.

When TELEGRAM_WEBHOOK_URL is set, the adapter starts an HTTP webhook
server (via python-telegram-bot's start_webhook()) instead of long
polling. This enables cloud platforms like Fly.io and Railway to
auto-wake suspended machines on inbound HTTP traffic.

Polling remains the default — no behavior change unless the env var
is set.

Env vars:
  TELEGRAM_WEBHOOK_URL    Public HTTPS URL for Telegram to push to
  TELEGRAM_WEBHOOK_PORT   Local listen port (default 8443)
  TELEGRAM_WEBHOOK_SECRET Secret token for update verification

Cherry-picked and adapted from PR #2022 by SHL0MS. Preserved all
current main enhancements (network error recovery, polling conflict
detection, DM topics setup).

Co-authored-by: SHL0MS <SHL0MS@users.noreply.github.com>
@teknium1 teknium1 merged commit 649d149 into main Mar 30, 2026
2 of 3 checks passed
itsXactlY pushed a commit to itsXactlY/hermes-agent that referenced this pull request Mar 30, 2026
…rch#3880)

When TELEGRAM_WEBHOOK_URL is set, the adapter starts an HTTP webhook
server (via python-telegram-bot's start_webhook()) instead of long
polling. This enables cloud platforms like Fly.io and Railway to
auto-wake suspended machines on inbound HTTP traffic.

Polling remains the default — no behavior change unless the env var
is set.

Env vars:
  TELEGRAM_WEBHOOK_URL    Public HTTPS URL for Telegram to push to
  TELEGRAM_WEBHOOK_PORT   Local listen port (default 8443)
  TELEGRAM_WEBHOOK_SECRET Secret token for update verification

Cherry-picked and adapted from PR NousResearch#2022 by SHL0MS. Preserved all
current main enhancements (network error recovery, polling conflict
detection, DM topics setup).

Co-authored-by: SHL0MS <SHL0MS@users.noreply.github.com>
raulbcs added a commit to raulbcs/hermes-agent that referenced this pull request Mar 30, 2026
teknium1 pushed a commit that referenced this pull request Mar 31, 2026
Documents the Telegram webhook mode from #3880:
- New 'Webhook Mode' section in telegram.md with polling vs webhook
  comparison, config table, Fly.io deployment example, troubleshooting
- Add TELEGRAM_WEBHOOK_URL/PORT/SECRET to environment-variables.md
- Add Telegram section to .env.example (existing + webhook vars)

Co-authored-by: raulbcs <raulbcs@users.noreply.github.com>
teknium1 added a commit that referenced this pull request Mar 31, 2026
Documents the Telegram webhook mode from #3880:
- New 'Webhook Mode' section in telegram.md with polling vs webhook
  comparison, config table, Fly.io deployment example, troubleshooting
- Add TELEGRAM_WEBHOOK_URL/PORT/SECRET to environment-variables.md
- Add Telegram section to .env.example (existing + webhook vars)

Co-authored-by: raulbcs <raulbcs@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants