1.0.5 • Published 5 months ago
mirza-ai-chatbox v1.0.5
Mirza Chat Box
A standalone JavaScript chat widget that can be easily integrated into any website with a simple script tag.
Features
Socket Connection
- Real-time communication with WebSocket
- Automatic reconnection
- Event-based messaging
Authentication System
- Login/signup functionality
- Token validation and storage
- Authentication state management
Support Mode Management
- Human support request/cancel functionality
- Support mode state management
- Persistence in localStorage
Message Rating System
- Message rating UI and functionality
- Optimistic updates and server responses
Typing Indicator
- Real-time typing status
- Socket events for typing status
Error Handling
- Comprehensive error handling
- User-friendly error messages
UI Improvements
- Message rendering with proper formatting
- Support for system messages
- Styling and animations
Localization Support
- Support for RTL languages
- Proper text direction
Debug Mode
- Optional debug information
- Developer tools
Performance Optimization
- Efficient message rendering
- Optimized DOM updates
Integration with jsDelivr CDN
You can easily integrate Mirza Chat Box into your website using jsDelivr CDN:
<!-- Add this to your HTML file -->
<script src="https://cdn.jsdelivr.net/npm/mirza-ai-chatbox@1.0.1/dist/mirza-chat-box.js"></script>
<script>
// Initialize the chat widget
window.addEventListener('DOMContentLoaded', function() {
MirzaChat.init({
apiUrl: 'https://your-api-url.com',
websiteId: 'your-website-id',
primaryColor: '#0066FF',
companyName: 'Your Company Name'
});
});
</script>
Using Data Attributes
You can also configure the chat widget using data attributes on the script tag:
<script
src="https://cdn.jsdelivr.net/npm/mirza-ai-chatbox@1.0.1/dist/mirza-chat-box.js"
data-api-url="https://your-api-url.com"
data-website-id="your-website-id"
data-primary-color="#0066FF"
data-company-name="Your Company Name"
data-position="bottom-right"
data-initial-message="Hello! How can I help you today?"
></script>
Using Global Configuration Variable
Another option is to set a global configuration variable before loading the script:
<script>
window.MIRZA_CHAT_CONFIG = {
apiUrl: 'https://your-api-url.com',
websiteId: 'your-website-id',
primaryColor: '#0066FF',
companyName: 'Your Company Name'
};
</script>
<script src="https://cdn.jsdelivr.net/npm/mirza-ai-chatbox@1.0.1/dist/mirza-chat-box.js"></script>
Usage
<script src="https://cdn.jsdelivr.net/npm/mirza-ai-chatbox@1.0.1/dist/mirza-chat-box.js"></script>
<script>
const chatBox = new MirzaChatBox({
apiUrl: 'https://api.example.com',
websiteId: 'your-website-id',
primaryColor: '#0066FF',
companyName: 'پشتیبان میرزا'
});
chatBox.init();
</script>
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
apiUrl | string | - | API endpoint for the chat service |
websiteId | string | - | Unique identifier for your website |
primaryColor | string | '#0066FF' | Primary color for the chat widget |
secondaryColor | string | '#E8F1FF' | Secondary color for the chat widget |
companyName | string | 'پشتیبان میرزا' | Company name displayed in the chat header |
position | string | 'bottom-right' | Position of the chat widget ('bottom-right' or 'bottom-left') |
initialMessage | string | 'سلام 😊 من میرزا چت هستم. چطور میتونم کمکتون کنم؟ 🤖' | Initial message shown when chat is opened |
API Methods
Once initialized, you can control the chat widget programmatically:
// Open the chat widget
MirzaChat.openChat();
// Close the chat widget
MirzaChat.closeChat();
// Update configuration dynamically
MirzaChat.updateConfig({
primaryColor: '#FF0000',
companyName: 'New Company Name'
});
Development
# Install dependencies
npm install
# Build for production
npm run build
# Development with hot reload
npm run dev
License
MIT