Metadata-Version: 2.4
Name: warnect
Version: 0.4.0
Summary: Python interface to arsya-baileys-open (WhatsApp Web) via a local Node.js bridge
Author: Arsya
License: MIT
Project-URL: Homepage, https://github.com/ziole-visa/warnect
Project-URL: Repository, https://github.com/ziole-visa/warnect
Project-URL: Issues, https://github.com/ziole-visa/warnect/issues
Project-URL: Changelog, https://github.com/ziole-visa/warnect/blob/main/CHANGELOG.md
Keywords: whatsapp,baileys,warnect,automation,bot
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-timeout>=2.3; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# warnect (Python)

Python client for WhatsApp Web multi-device, powered by **arsya-baileys-open**
through a local Node.js bridge.

- No browser, no Selenium.
- Bridge talks over stdio only — no TCP port is exposed.
- Session directory is created with `0700` permissions.
- Inputs validated, sends rate-limited, auto-reconnect with backoff.

## Requirements

- Python >= 3.10
- Node.js >= 20 and npm

## Install

```bash
pip install warnect
```

Node dependencies are installed automatically on first run. To install manually:

```bash
python -c "import warnect, pathlib; print(pathlib.Path(warnect.__file__).parent / 'bridge')"
cd <that-folder> && npm ci --omit=dev
```

## Quick start

```python
from warnect import BaileysClient

client = BaileysClient(auth_dir="auth")

def on_qr(qr):
    print("Scan QR:", qr)

def on_ready(data):
    print("Connected as:", data.get("user"))

def on_message(msg):
    print("Pesan:", msg.get("text"))
    if msg.get("text") == "ping":
        client.send_text(msg["chat"], "pong")

client.on("qr", on_qr)
client.on("ready", on_ready)
client.on("message", on_message)
client.start()

input("Bot jalan. Tekan Enter untuk stop...\n")
client.stop()
```

## Events

| Event        | Data                                          |
| ------------ | --------------------------------------------- |
| `qr`         | QR string (render/save it yourself)           |
| `connection` | `{ "status": "connecting" \| "open" \| "close" }` |
| `ready`      | `{ "user": {...} }`                            |
| `message`    | normalized message object                      |
| `error`      | `{ "code": "...", "message": "..." }`          |
| `reconnect`  | `{ "attempt": n, "delay": ms }`                |

## Message object

```python
{
  "id": "...",
  "chat": "123@s.whatsapp.net",
  "sender": "...",
  "fromMe": False,
  "isGroup": False,
  "type": "conversation",
  "text": "halo",
  "pushName": "Budi",
  "timestamp": 1730000000,
  "hasMedia": False,
  "fileName": None,
  "mimetype": None,
}
```

## API

| Method | Description |
| ------ | ----------- |
| `start(wait=True)` | Start bridge and socket |
| `ping()` | Health check |
| `send_text(jid, text)` | Send text |
| `send_image(jid, url=..., path=..., caption=...)` | Send image |
| `send_document(jid, path, filename=..., mimetype=..., caption=...)` | Send document |
| `request_pairing_code(number)` | Pairing code login |
| `send_presence(jid, presence)` | typing/paused/available |
| `send_read(jid, message_id)` | Mark message as read |
| `download_media(message_id)` | Download incoming media (bytes) |
| `get_groups(limit=100)` | List groups |
| `get_profile_picture(jid, type="image")` | Profile picture URL |
| `is_on_whatsapp(number)` | Check number |
| `logout()` | Log out session |
| `stop()` | Stop bridge |

## Async API

```python
import asyncio
from warnect import AsyncBaileysClient

async def main():
    client = AsyncBaileysClient(auth_dir="auth")

    async def on_message(msg):
        if msg.get("text") == "ping":
            await client.send_text(msg["chat"], "pong")

    client.on("message", on_message)
    await client.start()
    await asyncio.sleep(3600)
    await client.stop()

asyncio.run(main())
```

## CLI

```bash
warnect qr --auth-dir auth          # tampilkan QR
warnect pair --auth-dir auth --number 6281234567890
warnect send --auth-dir auth --to 62812xxx@s.whatsapp.net --text "hai"
warnect run --auth-dir auth         # jalankan + print event
```

## Media download

```python
def on_message(msg):
    if msg.get("hasMedia"):
        data = client.download_media(msg["id"])
        open("download.bin", "wb").write(data)
```

## Errors

```python
from warnect import BridgeError, BridgeTimeout, BridgeCrashed

try:
    client.send_text("123@s.whatsapp.net", "hi")
except BridgeTimeout:
    ...
except BridgeError as exc:
    print(exc.code, exc.message)
```

## Security notes

- The bridge uses local stdio; it does not open a network port.
- Node dependencies are pinned in `package-lock.json` and installed with `npm ci`.
- Keep `auth_dir` private; it contains WhatsApp session credentials.
- Use `min_send_interval` (default `0.5`s) to avoid spamming.

## License

MIT
