A modern, real-time chat system for WordPress that enables user-to-user communication with a self-hosted WebSocket server. Built with React, TypeScript, and Socket.IO for optimal performance and user experience.
- Instant messaging with WebSocket (Socket.IO) technology
- Live typing indicators to show when users are composing messages
- Connection status indicators for network reliability
- Message delivery status (pending, sent, delivered, read)
- Private messaging between users
- Group chat support (extensible for future features)
- Thread-based conversations with persistent history
- Message search and conversation filtering
- Unread message counters and notifications
- Responsive design built with Tailwind CSS
- React-powered frontend with TypeScript for type safety
- Dark/light mode support (customizable)
- Accessible interface following WCAG guidelines
- Mobile-optimized chat experience
- WordPress user integration with existing authentication
- API key authentication for secure server communication
- Permission-based access control for chat threads
- Data sanitization and validation
- Rate limiting and abuse prevention
- Optimistic UI updates for instant feedback
- Efficient database queries with proper indexing
- WebSocket fallback to REST API when needed
- Message pagination and lazy loading
- Minimal resource footprint
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β React Frontend β β Socket.IO Server β β WordPress Plugin β
β βββββΊβ βββββΊβ β
β - TypeScript β β - Node.js β β - PHP Classes β
β - Tailwind CSS β β - Express β β - REST API β
β - Real-time UI β β - WebSocket β β - Database β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
-
WordPress Plugin (
/wp-plugin/)- REST API endpoints for chat operations
- Database management and migrations
- User authentication and permissions
- Admin interface for configuration
-
Socket.IO Server (
/socket-server/)- Real-time WebSocket communication
- Event handling for messages, typing, presence
- WordPress API integration
- Connection management
-
React Frontend (
/wp-plugin/app/resources/)- Modern chat interface
- Real-time message handling
- Optimistic UI updates
- Connection status management
- WordPress 5.6+ with PHP 7.4+
- Node.js 16+ with npm or bun
- MySQL/MariaDB database
- Web server (Apache/Nginx) with WebSocket support
# Clone the repository
git clone https://github.com/Ri2rathod/chatpulse.git
cd chatpulse
# Install plugin in WordPress
cp -r wp-plugin/ /path/to/wordpress/wp-content/plugins/chatpulse/
# Install PHP dependencies
cd /path/to/wordpress/wp-content/plugins/chatpulse/
composer install# Navigate to plugin directory
cd wp-plugin/
# Install dependencies
npm install
# or
bun install
# Build for production
npm run build
# or
bun run build
# For development
npm run dev
# or
bun run dev# Navigate to server directory
cd socket-server/
# Install dependencies
npm install
# or
bun install
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Start server
npm start
# or
bun start
# For development with auto-reload
npm run dev
# or
bun run dev- Activate the plugin in WordPress admin
- Run database migrations via WP-CLI or admin interface:
wp chatpulse migrate:run --path=/path/to/wordpress
- Configure API settings in WordPress admin:
- Go to
Settings > Chatpulse API - Enable API access
- Generate API key
- Configure user permissions
- Go to
Create /socket-server/.env file:
# WordPress Integration
WP_BASE_URL=https://yoursite.com
WP_API_NAMESPACE=chatpulse-chat/v1
WP_API_KEY=your_generated_api_key_here
WP_API_TIMEOUT=10000
# Server Configuration
PORT=3001
NODE_ENV=production
# CORS Configuration
CORS_ORIGIN=https://yoursite.com
CORS_METHODS=GET,POST
# Socket.IO Configuration
SOCKET_PING_TIMEOUT=60000
SOCKET_PING_INTERVAL=25000-
Add the chat interface to any page/post using the shortcode:
[chatpulse-chat]
-
Start conversations by clicking the "New Chat" button
-
Send messages in real-time with typing indicators
-
Manage conversations from the sidebar
// Get user threads
GET /wp-json/chatpulse-chat/v1/threads
// Create new thread
POST /wp-json/chatpulse-chat/v1/threads
// Get thread messages
GET /wp-json/chatpulse-chat/v1/threads/{id}/messages
// Send message
POST /wp-json/chatpulse-chat/v1/threads/{id}/messages
// Update typing status
POST /wp-json/chatpulse-chat/v1/threads/{id}/typing
// Mark messages as read
POST /wp-json/chatpulse-chat/v1/threads/{id}/read// Client to Server
socket.emit('join_thread', { thread_id: 1 });
socket.emit('send_message', { thread_id: 1, content: 'Hello!' });
socket.emit('typing', { thread_id: 1, is_typing: true });
// Server to Client
socket.on('message_received', (message) => { /* handle */ });
socket.on('typing_status', (status) => { /* handle */ });
socket.on('user_joined', (user) => { /* handle */ });// Customize user chat permissions
add_filter('chatpulse_user_can_access_chat', function($can_access, $user, $request) {
return $user->has_cap('read'); // Customize logic
}, 10, 3);
// Modify thread access
add_filter('chatpulse_user_can_access_thread', function($can_access, $user_id, $thread_id, $thread) {
return true; // Customize access logic
}, 10, 4);
// Chat message sent hook
add_action('chatpulse_message_sent', function($message, $thread, $user) {
// Custom logic after message sent
}, 10, 3);The plugin creates these database tables:
wp_chatpulse_message_threads- Chat thread storagewp_chatpulse_messages- Individual messageswp_chatpulse_thread_participants- Thread membership (future)wp_chatpulse_message_reactions- Message reactions (future)
# Run migrations
wp chatpulse migrate:run
# Rollback migrations
wp chatpulse migrate:rollback
# Check migration status
wp chatpulse migrate:status
# Generate API key
wp chatpulse api:generate-key
# Test API connection
wp chatpulse api:test# Start WordPress development
cd wp-plugin/
bun run dev
# Start Socket.IO server development
cd socket-server/
bun run dev
# Watch for changes and auto-reload
# Frontend: Vite HMR enabled
# Backend: Nodemon for server restart- WordPress Health:
GET /wp-json/chatpulse-chat/v1/health - Socket.IO Health:
GET http://localhost:3001/health - Server Stats:
GET http://localhost:3001/stats
// Connection metrics
const stats = await chatService.getConnectionStats();
console.log('Active connections:', stats.connections);
console.log('Messages per second:', stats.messageRate);- API Keys: Rotate regularly and store securely
- Rate Limiting: Implement per-user message limits
- Input Validation: All messages are sanitized
- Permission Checks: Thread access validated per request
- CORS Configuration: Restrict origins in production
# Apache .htaccess
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"- Set
NODE_ENV=production - Configure proper CORS origins
- Set up SSL/TLS certificates
- Configure reverse proxy for WebSocket
- Set up database backups
- Configure log rotation
- Set up monitoring and alerts
# Example Dockerfile for Socket.IO server
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3001
CMD ["npm", "start"]We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Run tests:
npm test - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- PHP: WordPress Coding Standards
- JavaScript/TypeScript: ESLint + Prettier
- CSS: Tailwind CSS utility classes
- Commits: Conventional Commits specification
This project is licensed under the GPL-2.0+ License - see the LICENSE file for details.
- WordPress community for the robust platform
- Socket.IO team for real-time communication
- React and TypeScript teams for modern frontend tools
- Tailwind CSS for utility-first styling
- All contributors and users of this plugin
- Issues: GitHub Issues
- Documentation: Wiki
- Community: Discussions
Made with β€οΈ by Rathod Ritesh