Skip to content

feat: Telegram long-polling mode as alternative to webhooks#7363

Open
flobo3 wants to merge 3 commits intoagno-agi:mainfrom
flobo3:feat/telegram-long-polling
Open

feat: Telegram long-polling mode as alternative to webhooks#7363
flobo3 wants to merge 3 commits intoagno-agi:mainfrom
flobo3:feat/telegram-long-polling

Conversation

@flobo3
Copy link
Copy Markdown

@flobo3 flobo3 commented Apr 6, 2026

Problem

The Telegram interface currently only supports webhook mode, which requires a publicly accessible HTTPS URL, a FastAPI/uvicorn server, and TLS certificate management. This is overkill for local development, machines behind NAT, or simple single-process deployments.

Fixes #7362

Solution

Add mode="polling" to the Telegram class that runs without any web server:

from agno.os.interfaces.telegram import Telegram

tg = Telegram(
    team=team,
    mode="polling",
    token="...",
)
tg.run_polling()  # blocks, no web server needed

Architecture

Three new files, zero changes to existing code:

File Purpose
processor.py TelegramMessageProcessor — mirrors the processing logic from router.py closures into a reusable class
polling.py TelegramPolling — long-poll loop using bot.get_updates(offset, timeout) with background asyncio.create_task per message
telegram.py Updated — added mode param, start_polling() (async), run_polling() (sync)

router.py is completely untouched — full backward compatibility. All 117 existing tests pass without modification.

Key design decisions

  • No FastAPI dependency in polling moderun_polling() is pure asyncio, no uvicorn needed
  • Message conversiontelebot.types.Message → dict via .json() method, so process_message() receives the same format as webhook payloads
  • Background processing — each message is processed via asyncio.create_task() so the poll loop is never blocked
  • Graceful error recovery — polling errors trigger a 5-second backoff, then retry

Checklist

  • Backward compatible (webhook mode is unchanged, mode defaults to "webhook")
  • All 117 existing tests pass
  • Ruff clean
  • Self-review completed

@flobo3 flobo3 requested a review from a team as a code owner April 6, 2026 06:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

PR Triage

Missing tests: This PR modifies source code but does not include any test changes. Please add or update tests to cover your changes.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: add long-polling mode as alternative to webhooks

1 participant