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/<secret_key>/<project_key>/
Replace <secret_key> and <project_key> 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
const socket = new WebSocket('ws://127.0.0.1:8003/chatbot_api/<secret_key>/<project_key>/');
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:
{
"initialize_api": {}
}
Description: Initializes the API connection and retrieves the initial configuration and AIML data.
Response Example:
{
"status": true,
"title": "hello",
"disc": "hi",
"goal": "Basic",
"rules": "",
"api_key": "",
"aiml": "<category node_id=\"xparo_m0l3k1peb13suxsj7dr\"><pattern>HI</pattern><template></template></category>",
"maps": "",
"Sets": "",
"properties": "",
"System": ""
}
Command: Get Schedule
Command:
{
"xparo_get_schedule": {}
}
Description: Retrieves the current schedule of actions.
Response Example:
{
"schedule_control": {}
}
Command: Sync Configuration Files
Command:
{
"xparo_sync_config": {}
}
Description: Retrieves all configuration file paths.
Response Example:
{
"change_config": {
"xparo_name": "hello"
}
}
Command: Save AIML Content
Command:
{
"save_aiml": "aiml content here"
}
Description: Saves the provided AIML content to the server.
Command: Ask the Bot
Command:
{
"ask_bot": "your question here"
}
Description: Sends a question to the bot and retrieves the response based on the saved AIML data.
Response Example:
{
"message": {
"bot_response": "let's check this thing on internet"
}
}
Command: Control Schedule
Command:
{
"xparo_schedule_control": {}
}
Description: Modifies the robot’s schedule on the server.
Command: Delete Schedule
Command:
{
"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:
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.