Metadata-Version: 2.4
Name: approck-messaging
Version: 0.1.10
Summary: Pydantic message models and optional FastStream/Redis transport for Approck Telegram delivery.
Project-URL: Homepage, https://github.com/adalekin/approck-messaging
Project-URL: Repository, https://github.com/adalekin/approck-messaging
Project-URL: Issues, https://github.com/adalekin/approck-messaging/issues
Project-URL: Changelog, https://github.com/adalekin/approck-messaging/releases
Author-email: Aleksey Dalekin <adalekin@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Aleksey Dalekin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: faststream,messaging,pydantic,redis,telegram
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: pydantic[email]>=2.4.1
Provides-Extra: transport
Requires-Dist: faststream[redis]<0.6,>=0.5.9; extra == 'transport'
Description-Content-Type: text/markdown

# approck-messaging

Pydantic models and thin [FastStream](https://faststream.ag2.ai/) helpers for delivering Telegram-style messages over Redis streams. Used as the shared message contract between backend services and bots (for example with [`approck-aiogram-utils`](https://github.com/adalekin/approck-aiogram-utils)).

**Python:** 3.10+

## Install

From PyPI:

```bash
uv add approck-messaging
```

Or with pip:

```bash
pip install approck-messaging
```

Optional Redis transport (FastStream + Redis streams):

```bash
uv add "approck-messaging[transport]"
```

Core install includes only Pydantic models — no broker runtime.

## What is included

| Module | Purpose |
|--------|---------|
| `approck_messaging.models.message` | `Message`, `TransportMessage`, `MessageType`, `MessageMedia`, `MessageButton` |
| `approck_messaging.publisher` | `Publisher` — publish `TransportMessage` to a Redis stream |
| `approck_messaging.subscriber` | `Subscriber` — decorate handlers with `@subscriber.message(...)` |

## Usage

### Message models

`Message` describes the payload (caption, media, buttons, video note). `TransportMessage` adds routing metadata (`recipient`, optional `extra`, `valid_until`).

```python
from approck_messaging.models.message import (
    MessageMedia,
    MessageType,
    TransportMessage,
    TransportMessageRecipient,
)

message = TransportMessage(
    type=MessageType.GENERIC,
    caption="Hello",
    recipient=TransportMessageRecipient(telegram_id=123456789),
)
```

Supported `MessageType` values: `generic`, `video_note`.

### Publish to a Redis stream

Requires the `transport` extra (`faststream[redis]`).

```python
from faststream.redis import RedisBroker

from approck_messaging.models.message import MessageType, TransportMessage, TransportMessageRecipient
from approck_messaging.publisher import Publisher

broker = RedisBroker("redis://localhost:6379")
publisher = Publisher(broker=broker, stream="outbound-messages")

await publisher.send_message(
    TransportMessage(
        type=MessageType.GENERIC,
        caption="Hello",
        recipient=TransportMessageRecipient(telegram_id=123456789),
    )
)
```

`Publisher.from_uri(redis_uri, stream=...)` is a shortcut when you do not share a broker instance.

### Subscribe to a Redis stream

```python
from faststream import Context
from faststream.redis import RedisBroker, StreamSub

from approck_messaging.models.message import TransportMessage
from approck_messaging.subscriber import Subscriber

broker = RedisBroker("redis://localhost:6379")
subscriber = Subscriber(broker=broker, my_var=42)


@subscriber.message(StreamSub("outbound-messages", group="bot", consumer="1"))
async def handle(message: TransportMessage, my_var: int = Context()):
    assert my_var == 42
    ...
```

Extra keyword arguments passed to `Subscriber(...)` are registered as FastStream global context values (`context.set_global`).

## Development

```bash
uv sync --group dev --extra transport
uv run ruff check .
uv run ruff format --check .
uv run mypy approck_messaging
uv run pytest
```

## Related packages

- [`approck-aiogram-utils`](https://github.com/adalekin/approck-aiogram-utils) — send `Message` / `TransportMessage` payloads to Telegram via aiogram.

## License

MIT — see [LICENSE](LICENSE).
