This document provides a comprehensive guide to the MNotify-Copianto API, including authentication, endpoints, request/response formats, and WebSocket integration. The API provides functionalities for chat interactions, content management, vector database training, and conversation history.
https://your-production-url.comhttp://localhost:8000All API requests require authentication using an API key.
X-API-Key header:
X-API-Key: a1022ce5188258d89c5157db1a821db8b74d13aaeb0c0463e427ffff9d87d165
/api/endpoint?api_key=a1022ce5188258d89c5157db1a821db8b74d13aaeb0c0463e427ffff9d87d165
ws://example.com/ws/chat/a1022ce5188258d89c5157db1a821db8b74d13aaeb0c0463e427ffff9d87d165/
ws://{base_url}/ws/chat/{api_key}/Connect: Open a WebSocket connection to the endpoint
Handshake:
{
"type": "connection_established",
"message": "Connected to MNotify Bot"
}
{
"type": "chat_group_assigned",
"chat_group_id": "uuid-string",
"client_id": "uuid-string"
}
Sending Messages:
{
"type": "message",
"message": "Your question here",
"client_id": "optional-client-id",
"chat_group_id": "optional-group-id"
}
With Category Filtering:
{
"type": "message",
"message": "What policies do you know?",
"category_ids": ["Policy", "Regulation"], // Optional: filter by category names
"client_id": "optional-client-id",
"chat_group_id": "optional-group-id"
}
Receiving Streaming Responses:
{
"type": "token",
"token": "partial text chunk",
"is_streaming": true
}
{
"type": "streaming_complete",
"partial_message": "full message so far",
"is_streaming": false
}
{
"type": "message",
"message": "Complete response text",
"is_bot": true,
"conversation_id": "uuid-string",
"chat_group_id": "group-id",
"client_id": "client-id",
"timestamp": "2025-06-07T10:22:23.016Z",
"references": [
{
"title": "Document Title",
"source": "Source URL or description",
"category": "Category Name",
"reference_number": 1
}
],
"has_reference": true,
"reference_numbers": [1, 2],
"complete": true
}
{
"type": "message_delivered",
"conversation_id": "uuid-string",
"timestamp": "2025-06-07T10:22:25.016Z"
}
Handling Connection Issues:
| Type | Description | Direction |
|---|---|---|
connection_established |
Initial connection confirmation | Server → Client |
chat_group_assigned |
Assigns conversation grouping | Server → Client |
message |
User question or bot response | Bidirectional |
token |
Streaming partial response | Server → Client |
streaming_complete |
Indicates streaming is complete | Server → Client |
typing |
Bot typing indicator | Server → Client |
ping |
Connection heartbeat | Server → Client |
message_received |
Confirms receipt of user message | Server → Client |
error |
Error information | Server → Client |
history_request |
Request for conversation history | Client → Server |
chat_history |
Conversation history data | Server → Client |
message_delivered |
Confirms final message delivery | Server → Client |
/api/chat/categories/Response: List of categories
[
{
"id": 1,
"name": "Tax Policy",
"description": "Tax-related policies and regulations",
"created_at": "2025-06-07T10:22:23.016Z",
"updated_at": "2025-06-07T10:22:23.016Z"
}
]
/api/chat/categories/Request Body:
{
"name": "New Category",
"description": "Description of the category" // Optional
}
Response: Created category object
/api/chat/categories/{id}/Request Body:
{
"name": "Updated Category Name",
"description": "Updated description"
}
Response: Updated category object
/api/chat/categories/{id}/Response: 204 No Content
/api/chat/files/Query Parameters:
category: Filter by category IDtrained: Filter by training status (true/false)Response:
[
{
"id": 1,
"name": "File name",
"file": "/media/path/to/file.pdf",
"is_trained": false,
"show_as_reference": true,
"category": 1,
"category_name": "Category Name",
"created_at": "2025-06-07T10:22:23.016Z",
"updated_at": "2025-06-07T10:22:23.016Z"
}
]
/api/chat/files/Content-Type: multipart/form-data
Form Fields:
file: File data (required)name: File name (optional, defaults to filename)category: Category ID (optional)show_as_reference: Boolean (optional, default: true)Response: Created file object
/api/chat/files/batch/Content-Type: multipart/form-data
Form Fields:
files: Multiple file data (required)category: Category ID (optional)show_as_reference: Boolean (optional, default: true)Response: Array of created file objects
/api/chat/files/{id}/Response: 204 No Content
/api/chat/texts/Query Parameters:
category: Filter by category IDtrained: Filter by training status (true/false)Response: List of text objects
/api/chat/texts/Request Body:
{
"text": "Text content",
"name": "Text title",
"category": 1,
"show_as_reference": true
}
Response: Created text object
/api/chat/texts/batch/Request Body:
{
"texts": ["Text content 1", "Text content 2"],
"category": 1,
"show_as_reference": true
}
Response: Array of created text objects
/api/chat/texts/{id}/Response: 204 No Content
/api/chat/websites/Query Parameters:
category: Filter by category IDtrained: Filter by training status (true/false)ready: Filter by ready status (true/false)Response: List of website objects
/api/chat/websites/Request Body:
{
"url": "https://example.com",
"category": 1,
"show_as_reference": true,
"follow_links": false,
"is_js_heavy": false,
"wait_for_page_load": 15,
"wait_for_id": "",
"wait_for_class": "",
"ignore_urls": ""
}
Response: Created website object
/api/chat/websites/batch/Request Body:
{
"urls": ["https://example1.com", "https://example2.com"],
"category": 1,
"show_as_reference": true,
"follow_links": false,
"is_js_heavy": false,
"wait_for_page_load": 15,
"wait_for_id": "",
"wait_for_class": "",
"ignore_urls": ""
}
Response: Array of created website objects
/api/chat/websites/{id}/Response: 204 No Content
/api/chat/train/Response:
{
"task_id": "celery-task-id",
"status": "Training started"
}
/api/chat/status/Response:
{
"id": 1,
"index_name": "MN20250604123456",
"is_trained": true,
"new_data_added": false,
"last_trained_at": "2025-06-07T10:22:23.016Z",
"file_count": 10,
"text_count": 5,
"website_count": 3,
"untrained_count": 0,
"untrained_details": {
"files": [],
"texts": [],
"websites": [],
"not_ready_websites": [],
"count": {
"files": 0,
"texts": 0,
"websites": 0,
"not_ready_websites": 0,
"total": 0
}
},
"created_at": "2025-06-07T10:22:23.016Z",
"updated_at": "2025-06-07T10:22:23.016Z"
}
/api/chat/reset/Request Body:
{
"delete_weaviate_index": false
}
Response:
{
"message": "Bot training status reset successfully. All data sources marked for retraining."
}
/api/chat/task-status/{task_id}/Response:
{
"task_id": "task-id",
"status": "PENDING|IN_PROGRESS|COMPLETED|FAILED",
"result": {},
"task_type": "TRAINING",
"is_active": true
}
/api/chat/conversations/Query Parameters:
client_id: Filter by client ID (optional)chat_group_id: Filter by chat group ID (optional)Response:
{
"conversations": [
{
"id": 1,
"conversation_id": "uuid-string",
"client_id": "client-id",
"user_input": "Question text",
"chatbot_response": "Answer text",
"created_at": "2025-06-07T10:22:23.016Z",
"full_response": {},
"similar_docs": [],
"like_or_dislike": null
}
]
}
/api/chat/conversations/delete/{id}/Response: 204 No Content
/api/chat/settings/Note: This endpoint now only returns user-configurable fields.
Response:
{
"id": 1,
"name": "Ghana Policy Assistant",
"extra_prompt": "Always cite sources with reference numbers",
"created_at": "2025-06-07T10:22:23.016Z",
"updated_at": "2025-06-07T10:22:23.016Z"
}
/api/chat/settings/Note: Only name and extra_prompt fields can be updated.
Request Body:
{
"name": "Ghana Policy Bot",
"extra_prompt": "Focus on Ghana-specific regulations and always mention the source"
}
Response: Updated settings object (only exposed fields)
/api/chat/settings/Response: Default settings object
/api/chat/extract/content/Request Body:
{
"batch_size": 10,
"force": false
}
Response:
{
"message": "Content extraction started for 5 files",
"task_id": "uuid-string",
"total_files": 5,
"batch_size": 10,
"status": "PENDING"
}
/api/chat/extract/status//api/chat/extract/status/?task_id=<task_id>Response (without task_id):
{
"total_files": 10,
"extracted_files": 8,
"ready_files": 8,
"pending_files": 2,
"extraction_progress": 80.0,
"active_tasks": [
{
"task_id": "task-id",
"status": "IN_PROGRESS",
"created_at": "2025-06-07T10:22:23.016Z",
"result": {}
}
],
"active_task_count": 1
}
/api/chat/import/folder/Content-Type: multipart/form-data
Form Fields:
folder_zip: ZIP file with folder structurecategory (optional): Category IDshow_as_reference (optional): Boolean, default trueResponse:
{
"message": "Folder import started",
"task_id": "uuid-string",
"status": "PENDING"
}
/api/chat/import/status//api/chat/import/status/?task_id=<task_id>Response: Similar to extraction status
The API supports filtering bot responses based on specific content categories. This allows you to restrict the bot's knowledge base to specific topics or domains.
Include category_ids array with category names in your message:
{
"type": "message",
"message": "Tell me about tax policies",
"category_ids": ["Tax", "Finance"] // Filter by category names
}
If invalid categories are provided, you'll receive a warning:
{
"type": "warning",
"message": "Invalid category IDs: ['NonExistent']. Using valid categories only."
}
New endpoints for managing conversation history when WebSocket clients disconnect and need to restore their state.
/api/chat/client-history/Query Parameters:
client_id (required): The client ID from WebSocket connectionchat_group_id (optional): Filter by specific chat groupdate_from (optional): Filter from date (YYYY-MM-DD)date_to (optional): Filter to date (YYYY-MM-DD)limit (optional): Limit results (default: 50, max: 200)Response:
{
"client_id": "abc123",
"total_count": 25,
"conversations": [
{
"id": 1,
"conversation_id": "550e8400-e29b-41d4-a716-446655440000",
"client_id": "abc123",
"user_input": "What policies do you know?",
"chatbot_response": "I can help you with various policies...",
"created_at": "2025-01-15T10:30:00Z",
"full_response": {},
"similar_docs": [],
"like_or_dislike": null
}
],
"conversations_by_group": {
"group456": [/* conversations */]
},
"filters_applied": {
"chat_group_id": null,
"date_from": null,
"date_to": null,
"limit": 50
}
}
/api/chat/client-groups/Query Parameters:
client_id (required): The client IDResponse:
{
"client_id": "abc123",
"chat_groups": [
{
"chat_group_id": "group456",
"conversation_count": 15,
"last_message_at": "2025-01-15T10:30:00Z",
"first_message_at": "2025-01-14T08:00:00Z"
}
],
"total_groups": 2
}
/api/chat/conversation/{conversation_id}/Path Parameters:
conversation_id: UUID of the conversationResponse:
{
"conversation": {
"id": 1,
"conversation_id": "550e8400-e29b-41d4-a716-446655440000",
"client_id": "abc123",
"user_input": "What policies do you know?",
"chatbot_response": "I can help you with various policies...",
"created_at": "2025-01-15T10:30:00Z",
"full_response": {},
"similar_docs": [],
"like_or_dislike": null
},
"metadata": {
"client_id": "abc123",
"chat_group_id": "group456",
"created_at": "2025-01-15T10:30:00Z",
"has_response": true,
"has_references": true,
"user_feedback": null,
"related_conversations": 24
}
}
All API endpoints follow a consistent error response format:
{
"detail": "Error message"
}
or
{
"field_name": ["Error message"]
}
This section documents recent changes to the API that may require frontend updates.
category_ids field to message requestsGET /api/chat/client-history/ - Retrieve conversation history by client_idGET /api/chat/client-groups/ - List chat groups for a clientGET /api/chat/conversation/{conversation_id}/ - Get specific conversation detailsname and extra_prompt are now exposedmodel, temperature, prompt, use_default_prompt, max_tokens are no longer accessible via APIname from settingsextra_prompt is automatically integrated into bot behaviorcategory_ids: ["Tax", "Finance"] instead of category_ids: [1, 2]// Old way (if you were using categories)
{
"type": "message",
"message": "What policies?",
"category_ids": [1, 2] // Numeric IDs
}
// New way
{
"type": "message",
"message": "What policies?",
"category_ids": ["Tax", "Finance"] // Category names
}
// Use new client history endpoint after reconnection
const response = await fetch(`/api/chat/client-history/?client_id=${clientId}&limit=20`, {
headers: { 'X-API-Key': apiKey }
});
const { conversations } = await response.json();
// Restore UI with conversation history
For additional support or questions, please contact the backend development team.