$ show eternnoir/pyTelegramBotAPI
This repository is the `pyTelegramBotAPI` Python library, providing both synchronous (`TeleBot`) and asynchronous (`AsyncTeleBot`) implementations for building Telegram bots. It acts as a wrapper around the Telegram Bot API, handling all message types, inline queries, payments, webhooks, polling, and more. The library's architecture is layered: a user-facing bot class that exposes method calls to a core API helper module (`apihelper.py` / `asyncio_helper.py`), which performs HTTP requests to Telegram servers. Bot logic is structured via message handlers (decorator-based), custom filters, middleware hooks, and a state machine with pluggable storage backends (memory, Redis, pickle). Key entry points include `TeleBot` and `AsyncTeleBot` classes, with webhook support via `SyncWebhookListener` and `AsyncWebhookListener` in the `ext` module. The library relies on `requests` (sync) and `aiohttp` (async) for HTTP, with optional dependencies `redis`, `Pillow`, `fastapi`, `uvicorn`, and `watchdog`. It is extensively tested and documented, with over 50 examples covering typical bot patterns. While the codebase is mature and well-maintained, it exhibits some technical drift: duplicated sync/async helper modules, deprecated API parameters maintained for backward compatibility, and incomplete localization files. Overall, it is a solid, production-ready library for Telegram bot development.
The LLM identified 2 files worth highlighting for reuse:
Contains `antiflood` and `async_antiflood` functions that wrap any callable with automatic retry on HTTP 429 (rate limit) errors. The pattern is self-contained, relying only on `time`, `functools`, and `logging`. It is directly reusable in any project needing graceful rate-limit handling for external APIs, without any dependency on Telegram-specific code.
Defines `BaseStorage` abstract class with `get_data`, `set_data`, `delete_data`, `close` methods and a `get_context` context manager. This provides a reusable pattern for pluggable state storage in any application requiring per-user or per-chat data persistence. The class is purely abstract, importing only from `abc` and `typing`, making it easily extractable and adaptable to different backends (memory, Redis, database).