Metadata-Version: 2.4
Name: aiogram-buffered-router
Version: 0.1.0
Summary: Debounced message batching router for aiogram 3
Project-URL: Homepage, https://github.com/wprhvso/aiogram-buffered-router
Project-URL: Repository, https://github.com/wprhvso/aiogram-buffered-router
Project-URL: Issues, https://github.com/wprhvso/aiogram-buffered-router/issues
Author: wprhvso
License-Expression: MIT
License-File: LICENSE
Keywords: aiogram,batching,bot,debounce,telegram
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: aiogram>=3.22
Description-Content-Type: text/markdown

# aiogram-buffered-router

Debounced message batching for aiogram 3. Consecutive messages from the same chat are collected into one batch and passed to a single handler.

## Install

```
uv add aiogram-buffered-router
```

## Usage

```python
from aiogram import Bot, Dispatcher, F
from aiogram.types import Message
from aiogram_buffered_router import BufferedRouter

router = BufferedRouter(name="chat", interval=1.0)


@router.buffered(F.text)
async def handle_batch(messages: list[Message], data: dict[str, object]) -> None:
    bot = data["bot"]
    texts = [message.text for message in messages if message.text]
    print(bot, texts)


dispatcher = Dispatcher()
dispatcher.include_router(router)
```

On shutdown flush the pending batches:

```python
await router.aclose()
```

## Options

- `interval` — debounce window in seconds, restarted on nothing; the batch is dispatched `interval` seconds after the first message.
- `max_size` — dispatch immediately once the batch reaches this size, `0` disables the limit.
- `key` — `chat_key` (bot + chat) or `thread_key` (bot + chat + topic, default), or any callable returning a hashable.

Handler exceptions are logged by the `aiogram_buffered_router.buffer` logger and never break polling.

## License

MIT
