Xparo WebSocket API Documentation ================================= The **Xparo WebSocket API** provides real-time communication with the Xparo server. This API allows you to send commands, receive responses, and interact dynamically with your chatbot using WebSockets. WebSocket Connection URL ------------------------ To establish a WebSocket connection, use the following URL: ws://127.0.0.1:8003/chatbot_api/// Replace `` and `` with your specific keys. Connecting to the WebSocket API ------------------------------- To connect to the WebSocket API, use a WebSocket client (e.g., JavaScript WebSocket API, Python `websockets` library). The connection will enable real-time communication with the Xparo chatbot server. Example JavaScript Connection Code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: javascript const socket = new WebSocket('ws://127.0.0.1:8003/chatbot_api///'); socket.onopen = function(event) { console.log('WebSocket connection established'); }; socket.onmessage = function(event) { console.log('Received from server:', event.data); }; socket.onclose = function(event) { console.log('WebSocket connection closed'); }; socket.onerror = function(error) { console.error('WebSocket error:', error); }; Commands Overview ----------------- Once connected, you can send different commands through the WebSocket to interact with the chatbot and manage server settings. Below is a list of the available commands and their expected responses. Command: Initialize API ~~~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "initialize_api": {} } - **Description**: Initializes the API connection and retrieves the initial configuration and AIML data. **Response Example:** .. code-block:: json { "status": true, "title": "hello", "disc": "hi", "goal": "Basic", "rules": "", "api_key": "", "aiml": "HI", "maps": "", "Sets": "", "properties": "", "System": "" } Command: Get Schedule ~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "xparo_get_schedule": {} } - **Description**: Retrieves the current schedule of actions. **Response Example:** .. code-block:: json { "schedule_control": {} } Command: Sync Configuration Files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "xparo_sync_config": {} } - **Description**: Retrieves all configuration file paths. **Response Example:** .. code-block:: json { "change_config": { "xparo_name": "hello" } } Command: Save AIML Content ~~~~~~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "save_aiml": "aiml content here" } - **Description**: Saves the provided AIML content to the server. Command: Ask the Bot ~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "ask_bot": "your question here" } - **Description**: Sends a question to the bot and retrieves the response based on the saved AIML data. **Response Example:** .. code-block:: json { "message": { "bot_response": "let's check this thing on internet" } } Command: Control Schedule ~~~~~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "xparo_schedule_control": {} } - **Description**: Modifies the robot's schedule on the server. Command: Delete Schedule ~~~~~~~~~~~~~~~~~~~~~~~~ - **Command**: .. code-block:: json { "xparo_delete_schedule_control": {} } - **Description**: Deletes the robot's schedule on the server. Error Handling -------------- Ensure you handle WebSocket errors correctly to maintain a stable connection and retry logic where necessary. Here's an example of handling common WebSocket errors: .. code-block:: javascript socket.onerror = function(error) { console.error('WebSocket error:', error); // Implement reconnection logic here }; Conclusion ---------- This documentation provides an overview of how to connect and interact with the Xparo WebSocket API. Utilize these commands effectively to manage your AIML content, schedules, and chatbot interactions in real-time. .. raw:: html .. raw:: html .. raw:: html
.. raw:: html