Skip to content

feat(telegram): support long polling, so Telegram survives a private-network install #2849

Open

Description

@obasilakis

Summary

Trinity drives Telegram by webhook only. src/backend/adapters/transports/telegram_webhook.py calls setWebhook, handing Telegram a URL its servers then make inbound HTTPS requests to. Add the Bot API's outbound alternative — getUpdates long polling — so a Telegram binding keeps working on an instance with no publicly reachable address.

Verified: grep -rn "getUpdates" src/ docker/ returns zero hits. Webhook is the only transport implemented.

Why it matters

On a private-network install (Tailscale, or any instance behind a VPN with the public ports closed), the tailnet address is in 100.64.0.0/10 — carrier-grade NAT, not routable from Telegram's servers — so the webhook never arrives and the binding is dead.

The hardening guide has to tell operators this, and it currently reads as a Telegram limitation:

| Telegram, WhatsApp, VoIP | Work | Broken |

It is not. WhatsApp (Twilio) and VoIP genuinely have to call in. Telegram does not — the Bot API offers long polling, which is outbound and would survive a tailnet exactly as Slack's Socket Mode already does (src/backend/adapters/transports/slack_socket.py). Slack is the one integration in that table that survives a private network, and it survives for precisely this reason.

So Trinity has the pattern already; Telegram just never got it.

Acceptance Criteria

  • A Telegram binding can run in polling mode, chosen per binding or per instance — a webhook install is unaffected and nothing silently switches
  • Mode is explicit in Settings, and the UI says which one a binding is using and what each needs (polling: no public address; webhook: a reachable HTTPS URL)
  • Switching to polling calls deleteWebhook first — Telegram refuses getUpdates while a webhook is registered, and the error is unhelpful
  • Polling runs under a leader lease like every other background loop (Invariant: every loop starts in EVERY uvicorn worker — see docs/memory/architecture/background-services.md), so N workers do not each consume updates and drop messages for the others
  • offset is persisted across restarts, or a restart re-delivers or skips updates
  • Failure is visible: a polling loop that has stopped surfaces the same way a failed webhook registration does, rather than a bot that has quietly gone silent
  • The hardening guide's Step 2 table stops calling this broken, and the note added there pointing at this issue is removed

Notes

  • Long polling holds an open HTTP request to api.telegram.org for up to the timeout, so the loop wants its own connection handling rather than the shared short-lived client.
  • Slack's Socket Mode transport is the closest existing shape to copy — outbound, long-lived, leader-gated.
  • Scope is the transport only. Nothing about how a normalized message is handled afterwards should change; ChannelAdapter (Invariant 9) already sits above this.

Found while rewriting the marketplace hardening guide (#2692): the guide could not honestly explain the Broken cell without naming it as our gap.

Refs #2692

Activity

  1. added
    priority-p2
    type-feature
    theme-reliability
    on Sep 16, 2026
  2. added
    status-ready
    complexity-high
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-highpriority-p2status-readytheme-reliabilitytype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions