A fully functional React chatbot widget with modern UI/UX features including file upload, feedback system, and persistent storage.
- Interactive Chat Interface: Real-time streaming chat with markdown support
- Document Q&A: Upload PDF files and ask questions about their content
- File Upload: Support for PDF, DOCX, and TXT files (up to 3 files, 10MB each)
- Feedback System: Upvote/downvote per message + overall chat rating
- Persistent Storage: Messages and feedback saved to localStorage
- API Health Monitoring: Automatic health checks with retry logic
- Customizable: Light/dark themes, positioning, bot name configuration
- Smooth Animations: Powered by Framer Motion
- Error Handling: Graceful error boundaries and user-friendly error messages
- Responsive Design: Works on desktop and mobile devices
- React 18 with TypeScript
- Vite for fast development and building
- TailwindCSS for styling
- React Hook Form for form management
- Zustand for state management
- Framer Motion for animations
- React Markdown for message rendering
- Lucide React for icons
- Clone the repository:
git clone <repository-url>
cd chatbot-widget- Install dependencies:
npm install- Create a
.envfile in the root directory:
VITE_API_BASE_URL=your-api-base-url
VITE_API_KEY=your-api-key- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:3000
Create a .env file in the root directory with the following variables:
VITE_API_BASE_URL=http://your-api-server.com # Your backend API URL
VITE_API_KEY=your-api-key # Optional: API key for authenticationThe widget expects the following API endpoints:
Chat Endpoints:
POST /api/v1/chat- Send a chat message and receive responsePOST /api/v1/chat/stream- Streaming chat responses (SSE)
Document Endpoints:
POST /api/v1/documents/upload- Upload PDF filePOST /api/v1/documents/qa- Ask questions about uploaded documents (supports streaming)
Health Check:
GET /api/v1/health- API health status
See src/services/ for detailed API interface definitions.
| Prop | Type | Default | Description |
|---|---|---|---|
botName |
string |
'AI Assistant' |
Name displayed in the chat header |
theme |
'light' | 'dark' |
'light' |
Color theme for the widget |
position |
'bottom-right' | 'bottom-left' |
'bottom-right' |
Position of the chat bubble |
allowUpload |
boolean |
true |
Enable/disable file upload functionality |
src/
βββ components/
β βββ ChatBubble.tsx # Floating chat button
β βββ ChatWindow.tsx # Main chat interface
β βββ ChatbotWidget.tsx # Main widget component
β βββ ErrorBoundary.tsx # Error boundary wrapper
β βββ FeedbackButtons.tsx # Message rating buttons
β βββ FeedbackModal.tsx # Chat feedback form
β βββ FileUpload.tsx # File upload component
β βββ MessageInput.tsx # Message input with form
β βββ MessageItem.tsx # Individual message display
β βββ MessageWithFeedback.tsx # Memoized message wrapper
βββ store/
β βββ slices/
β β βββ feedbackSlice.ts # Feedback state management
β β βββ messageSlice.ts # Message state management
β β βββ uiSlice.ts # UI state management
β β βββ uploadSlice.ts # File upload state management
β βββ useChatStore.ts # Main Zustand store
βββ services/
β βββ api/
β β βββ client.ts # API client and error handling
β βββ chatService.ts # Chat API integration
β βββ documentService.ts # Document Q&A and upload
β βββ healthService.ts # API health checks
βββ hooks/
β βββ useAPIHealth.ts # API health monitoring hook
βββ constants/
β βββ index.ts # Application constants
βββ types/
β βββ index.ts # TypeScript interfaces
βββ App.tsx # Demo application
βββ main.tsx # Application entry point
βββ index.css # Global styles
Application constants are centralized in src/constants/index.ts:
- FILE_UPLOAD: File upload limits and allowed types
- HEALTH_CHECK: API health check intervals and retry delays
- STREAMING: Streaming simulation delays and chunk sizes
- CHAT: Chat configuration (e.g., max conversation history)
- UI: UI-related constants (e.g., textarea height, file name width)
The widget supports light and dark themes. You can customize the colors by modifying the theme classes in each component.
All components use TailwindCSS classes and can be easily customized by modifying the className props.
Animations are handled by Framer Motion. You can customize animations by modifying the motion props in each component.
- Streaming Responses: Real-time streaming of AI responses using Server-Sent Events (SSE)
- Markdown Support: Bot messages support markdown formatting
- Conversation History: Last 10 messages sent as context to the API
- Auto-scroll: Automatically scrolls to the latest message
- Loading States: Visual indicators for message processing
- Upload PDF files and ask questions about their content
- Streaming responses for document-based queries
- File upload status indicators (uploading, success, error)
- Support for multiple file uploads (max 3 files)
- Supported Formats: PDF, DOCX, and TXT files
- Limits: Maximum 3 files, 10MB each
- Validation: Client-side validation for file type and size
- Error Handling: Clear error messages for upload failures
- Visual Feedback: Upload progress and status indicators
- Message Rating: Thumbs up/down for individual bot messages
- Overall Rating: 5-star rating system when closing the chat
- Comments: Optional text feedback field
- Persistence: All feedback saved to localStorage
- Automatic Checks: Health check every 30 seconds while chat is open
- Retry Logic: Faster retry (5 seconds) on health check failure
- Status Indicator: Visual health status in chat header
- Error Recovery: Graceful handling of API unavailability
Enter: Send messageShift + Enter: New line in message inputEsc: Close feedback modal
The widget uses Zustand with a modular slice pattern for state management:
-
Message Slice (messageSlice.ts)
- Add, update, and clear messages
- Handle streaming and loading states
- Message history management
-
Feedback Slice (feedbackSlice.ts)
- Per-message feedback (upvote/downvote)
- Overall chat feedback with ratings and comments
- Feedback persistence
-
UI Slice (uiSlice.ts)
- Chat open/closed state
- Minimized state
- API health status monitoring
- Last health check timestamp
-
Upload Slice (uploadSlice.ts)
- File upload state management
- Uploaded files tracking
- Clear uploaded files
- Uses Zustand persist middleware
- Stores messages, feedback, and chat feedback in localStorage
- Custom merge logic for state hydration
- Version management for migrations
npm run buildThe built files will be in the dist directory, ready for deployment.
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For questions or issues, please open an issue on the repository.