Metadata-Version: 2.5
Name: wconnect
Version: 0.1.0
Summary: Messaging library with Telegram and Slack integration for sending and receiving messages
Project-URL: Homepage, https://github.com/wisrovi/wconnect
Project-URL: Documentation, https://wconnect.readthedocs.io/en/latest/
Project-URL: Repository, https://github.com/wisrovi/wconnect
Project-URL: Issues, https://github.com/wisrovi/wconnect/issues
Project-URL: Changelog, https://github.com/wisrovi/wconnect/blob/main/CHANGELOG.md
Author-email: William Steve Rodriguez Villamizar <wisrovi.rodriguez@gmail.com>
License: MIT License
        
        Copyright (c) 2025 William Rodriguez
        
        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: bot,chat,messaging,notifications,slack,telegram
Classifier: Development Status :: 3 - Alpha
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.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Chat
Requires-Python: >=3.9
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: python-telegram-bot>=21.0
Requires-Dist: requests>=2.31.0
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: mypy>=1.7.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest>=7.4.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: myst-parser>=2.0.0; extra == 'docs'
Requires-Dist: sphinx-copybutton>=0.5.0; extra == 'docs'
Requires-Dist: sphinx-design>=0.5.0; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == 'docs'
Requires-Dist: sphinx-sitemap>=2.5.0; extra == 'docs'
Requires-Dist: sphinx>=7.2.0; extra == 'docs'
Description-Content-Type: text/markdown

# wconnect (wmessenger)

`wconnect` (`wmessenger`) es una librería en Python diseñada para simplificar la creación de bots e integración con plataformas de mensajería (Telegram). Ofrece abstracciones orientadas a objetos, soporte para el protocolo Context Manager (`with`), descarga automática de archivos adjuntos (`auto_save_in`), y decoradores intuitivos compatibles con la convención de `wkafka` y `wredis`.

---

## 🛠️ Tecnologías y Librerías Relevantes

Este componente utiliza las siguientes tecnologías y librerías clave de su ecosistema:

- **[python-telegram-bot](https://python-telegram-bot.org/)**: Cliente asíncrono para interactuar con la Telegram Bot API y gestionar la infraestructura de handlers y polling/webhooks.
- **[wauth](https://pypi.org/project/wauth/)**: Librería del ecosistema para almacenamiento seguro y encriptado de credenciales, tokens y lista de usuarios autorizados.
- **[requests](https://requests.readthedocs.io/)**: Cliente HTTP síncrono para envíos directos y descarga de archivos binarios desde Telegram CDN.
- **[aiohttp](https://docs.aiohttp.org/)**: Motor HTTP asíncrono para operaciones I/O sin bloqueo.

---

## 📦 Instalación

```bash
pip install wconnect
```

---

## 🔐 Métodos de Autenticación

`wconnect` soporta 3 formas flexibles para inicializar el cliente `Wtelegram`:

### 1. Vía WAuth Vault (Base de Datos Encriptada)
```python
from wauth import WAuth
from wconnect import Wtelegram

vault = WAuth(db_path="./my_secrets.db")
bot = Wtelegram(auth_instance=vault)
```

### 2. Vía Token Directo
```python
from wconnect import Wtelegram

bot = Wtelegram(token="8823336064:AAE2sky0B4vOD5_z2cKsDekv4T9LSKiSlGA")
```

### 3. Vía Variable de Entorno (`TELEGRAM_BOT_TOKEN`)
```bash
export TELEGRAM_BOT_TOKEN="8823336064:AAE2sky0B4vOD5_z2cKsDekv4T9LSKiSlGA"
```
```python
from wconnect import Wtelegram

bot = Wtelegram()  # Detecta automáticamente TELEGRAM_BOT_TOKEN
```

---

## 📥 Recepción de Mensajes (Receiver)

Permite registrar escuchadores mediante decoradores como `@bot.on_command(...)` y `@bot.on_message(...)` o `@bot.consumer(...)`.

### Ejemplo con Descarga Automática (`auto_save_in` y `saved_path`)

```python
from wconnect import WMessage, Wtelegram

# auto_save_in descarga imágenes y documentos en ./downloads sin código adicional
bot = Wtelegram(token="YOUR_BOT_TOKEN", auto_save_in="./downloads")


@bot.on_command(command="status")
def handle_status(message: WMessage) -> None:
    bot.send(to=message.chat_id, message="Servicio Online ✅")


@bot.on_message(value_type="image")
def handle_image(message: WMessage) -> None:
    print(f"Imagen guardada automáticamente en: {message.saved_path}")


@bot.on_message(value_type="document")
def handle_document(message: WMessage) -> None:
    print(f"Archivo guardado automáticamente en: {message.saved_path}")


# Mismo estándar de consumo que wkafka / wredis
bot.run_consumers(block=True)
```

---

## 📤 Envío de Contenido (Sender)

Soporta envíos de texto, imágenes (auto-detectando si es URL o archivo local) y documentos utilizando el protocolo Context Manager (`with`):

```python
from wconnect import WFile, Wtelegram

with Wtelegram(token="YOUR_BOT_TOKEN") as producer:
    # 1. Mensaje de Texto
    producer.send(to="CHAT_ID", message="✅ Operación completada")

    # 2. Imagen desde URL o Ruta Local
    producer.send_image(
        to="CHAT_ID",
        url="https://httpbin.org/image/png",
        caption="Gráfico Analytics",
    )

    # 3. Documento en memoria (WFile) o desde disco
    data_bytes = b"id,value\n1,100"
    doc_file = WFile(content=data_bytes, name="report.csv")
    producer.send_document(to="CHAT_ID", file=doc_file)
```

---

## 📁 Estructura de Ejemplos

Puedes consultar ejemplos listos para ejecutar en la carpeta `examples/01 telegram/`:

- **`00 config/`**: Formas de inicialización (Vault, Token Directo, Env Var).
- **`01 receiver/`**: Casos de uso de recepción (`01 text`, `02 image`, `03 document`, `04 command`, `05 all`).
- **`02 sender/`**: Casos de uso de envío (`01 text`, `02 image`, `03 document`).

---

## 📄 Licencia
MIT License - Copyright (c) 2025 William Rodriguez