Skip to content

Commit fea7a88

Browse files
committed
feat: extend message types and introduce FFI bridge for custom store backends via SqliteStore rename
1 parent 4c2dfbd commit fea7a88

23 files changed

Lines changed: 787 additions & 41 deletions

Cargo.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ tracing = "0.1.41"
2626
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "fmt"] }
2727
chrono = "0.4.44"
2828
infer = { git = "https://github.com/bojand/infer", branch = "master" }
29+
libloading = "0.8"
30+
serde_json = "1"
31+
bincode = "1"
32+
bytes = "1"
33+
serde = { version = "1", features = ["derive"] }
34+
wacore-appstate = { path = "libs/whatsapp-rust/wacore/appstate" }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ uv run maturin build --release
8989

9090
```python
9191
import asyncio
92-
from tryx.backend import SqliteBackend
92+
from tryx.backend import SqliteStore
9393
from tryx.client import Tryx, TryxClient
9494
from tryx.events import EvMessage
9595
from tryx.waproto.whatsapp_pb2 import Message
9696

97-
backend = SqliteBackend("whatsapp.db")
97+
backend = SqliteStore("whatsapp.db")
9898
app = Tryx(backend)
9999

100100
@app.on(EvMessage)

docs/getting-started/authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Tryx follows the WhatsApp multi-device pairing flow. The first run links a sessi
3434
Use a stable backend path:
3535

3636
```python
37-
from tryx.backend import SqliteBackend
37+
from tryx.backend import SqliteStore
3838

39-
backend = SqliteBackend("/srv/tryx/session.db")
39+
backend = SqliteStore("/srv/tryx/session.db")
4040
```
4141

4242
If the same backend path is reused, you usually do not need to pair again.

docs/getting-started/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Typical wheel output appears under `target/wheels/`.
4040

4141
```python
4242
from tryx.client import Tryx, TryxClient
43-
from tryx.backend import SqliteBackend
43+
from tryx.backend import SqliteStore
4444

45-
backend = SqliteBackend("whatsapp.db")
45+
backend = SqliteStore("whatsapp.db")
4646
app = Tryx(backend)
4747
client = app.get_client()
4848
print(type(client).__name__)

docs/getting-started/quickstart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Build and run a minimal echo client, then expand it safely.
1010
```python
1111
import asyncio
1212

13-
from tryx.backend import SqliteBackend
13+
from tryx.backend import SqliteStore
1414
from tryx.client import Tryx, TryxClient
1515
from tryx.events import EvMessage
1616
from tryx.waproto.whatsapp_pb2 import Message
1717

18-
backend = SqliteBackend("whatsapp.db")
18+
backend = SqliteStore("whatsapp.db")
1919
app = Tryx(backend)
2020

2121

@@ -68,10 +68,10 @@ if __name__ == "__main__":
6868
For quick scripts without manual event loop management:
6969

7070
```python
71-
from tryx.backend import SqliteBackend
71+
from tryx.backend import SqliteStore
7272
from tryx.client import Tryx
7373

74-
app = Tryx(SqliteBackend("whatsapp.db"))
74+
app = Tryx(SqliteStore("whatsapp.db"))
7575
app.run_blocking()
7676
```
7777

docs/tutorials/command-bot.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Build a command-driven automation that stays maintainable as command count grows
1313
```python
1414
import asyncio
1515

16-
from tryx.backend import SqliteBackend
16+
from tryx.backend import SqliteStore
1717
from tryx.client import Tryx, TryxClient
1818
from tryx.events import EvMessage
1919

20-
backend = SqliteBackend("whatsapp.db")
20+
backend = SqliteStore("whatsapp.db")
2121
app = Tryx(backend)
2222

2323

examples/command_bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import segno
1818

19-
from tryx.backend import SqliteBackend
19+
from tryx.backend import SqliteStore
2020
from tryx.client import Tryx, TryxClient
2121
from tryx.events import EvMessage, EvPairingQrCode, EvPushNameUpdate, EvUserAboutUpdate
2222

@@ -41,7 +41,7 @@ def _download() -> bytes:
4141
return await asyncio.to_thread(_download)
4242

4343

44-
backend = SqliteBackend(DB_PATH)
44+
backend = SqliteStore(DB_PATH)
4545
app = Tryx(backend)
4646

4747

libs/whatsapp-rust

python/tryx/backend.pyi

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
"""Backend interfaces for Tryx runtime state storage."""
22

33
from abc import ABC
4+
from typing import Optional
45

56
class BackendBase(ABC):
67
"""Base class for all backend implementations used by Tryx."""
78

8-
class SqliteBackend(BackendBase):
9-
"""SQLite-backed backend implementation.
9+
class SqliteStore(BackendBase):
10+
"""SQLite-backed storage implementation.
1011
1112
Use this backend to persist session and app-state data in a local file.
1213
"""
1314

1415
path: str
1516

1617
def __init__(self, path: str) -> None:
17-
"""Create a SQLite backend bound to a database file path."""
18+
"""Create a SQLite storage backend bound to a database file path."""
1819
...
20+
21+
22+
from typing import Protocol, runtime_checkable
23+
24+
@runtime_checkable
25+
class FfiStoreProtocol(Protocol):
26+
"""
27+
Protocol defining an external FFI store via duck typing.
28+
Any Python object with `lib_path` and `config_json` attributes
29+
will be dynamically accepted by Tryx as an FFI store backend.
30+
"""
31+
@property
32+
def lib_path(self) -> str: ...
33+
@property
34+
def config_json(self) -> str: ...

0 commit comments

Comments
 (0)