Quick Start¶
Build and run a minimal echo client, then expand it safely.
Expected outcome
You should receive incoming text and reply with an echo message in the same chat.
Minimal Client¶
import asyncio
from tryx.backend import SqliteBackend
from tryx.client import Tryx, TryxClient
from tryx.events import EvMessage
from tryx.waproto.whatsapp_pb2 import Message
backend = SqliteBackend("whatsapp.db")
app = Tryx(backend)
@app.on(EvMessage)
async def on_message(client: TryxClient, event: EvMessage) -> None:
text = event.data.get_text() or "<non-text>"
chat = event.data.message_info.source.chat
await client.send_message(chat, Message(conversation=f"Echo: {text}"))
async def main() -> None:
await app.run()
if __name__ == "__main__":
asyncio.run(main())
How It Works¶
- backend persists pairing/session state
Tryxruntime wires event dispatcher@app.on(EvMessage)registers handlerTryxClientexecutes namespace/root API calls
Runtime Flow¶
- Create backend storage.
- Create
Tryxclient instance. - Register handlers with
@app.on(EventClass). - Start runtime with
await app.run(). - Use
TryxClientinside handlers for API calls.
First Production Hardening¶
- deduplicate with message id
- bound retries for network operations
- validate command input
- keep admin-only commands restricted
- keep handlers short
- offload heavy work to worker queue
Blocking Script Mode¶
For quick scripts without manual event loop management:
from tryx.backend import SqliteBackend
from tryx.client import Tryx
app = Tryx(SqliteBackend("whatsapp.db"))
app.run_blocking()
Warning
run_blocking() is convenient for small scripts. Prefer explicit async runtime control for larger systems.
Next Steps¶
- Read Authentication Flow to understand pairing and session persistence.
- Explore Client API Gateway for all namespace methods.
- Review Event Model before building complex logic.
- Continue with Tutorial: Command Automation.