WebSocket API ============= The **XPARO WebSocket API** enables real-time communication between robots, clients, and the XPARO platform. Unlike REST, WebSocket maintains a persistent connection that allows the server to push updates instantly. WebSocket endpoint ------------------ ``` wss://xparo-website.onrender.com/ws/chatbot/// ``` Connection flow --------------- 1. Client connects to the WebSocket endpoint. 2. Server authenticates using ``secret_key`` and ``project_id``. 3. Server may push configuration updates immediately. 4. Client sends messages; the server responds or pushes asynchronous events. Message format -------------- All messages are JSON objects. Basic structure: .. code-block:: json { "type": "message_type", "data": {} } Client → Server examples ------------------------ **Chat** .. code-block:: json { "type": "chat", "data": { "message": "Hello robot", "robot_id": "robot_123" } } Server response: .. code-block:: json { "type": "chat_response", "data": { "response": "Hello, how can I assist you?" } } **Telemetry update** .. code-block:: json { "type": "telemetry", "data": { "cpu_usage": 42, "memory_usage": 63, "disk_usage": 31 } } Server → Client events ----------------------- **Chat response** .. code-block:: json { "type": "chat_response", "data": { "response": "Navigation command received" } } **Behavior tree update** .. code-block:: json { "type": "behavior_update", "data": { "tree_name": "MainTree", "xml": "..." } } **Remote control** .. code-block:: json { "type": "remote_command", "data": { "command": "start_navigation", "parameters": { "goal": "table_4" } } } **Logging session start** .. code-block:: json { "type": "log_updated", "data": { "session_id": "session_987" } } **REST token update** .. code-block:: json { "type": "REST_API_TOKEN", "data": { "token": "abcdef123456" } } Heartbeat --------- Server ping: .. code-block:: json { "type": "ping" } Client should reply with: .. code-block:: json { "type": "pong" } Example Python client --------------------- .. code-block:: python import websocket import json url = "wss://xparo-website.onrender.com/ws/chatbot/SECRET/PROJECT/" def on_message(ws, message): data = json.loads(message) print("Received:", data) def on_open(ws): payload = { "type": "chat", "data": { "message": "Hello robot" } } ws.send(json.dumps(payload)) ws = websocket.WebSocketApp( url, on_message=on_message ) ws.run_forever() .. raw:: html .. raw:: html .. raw:: html
.. raw:: html