The chatbot uses OpenAI GPT-3.5-turbo for intelligent responses to user queries. When OpenAI API is unavailable, it falls back to predefined responses for common questions.
- User sends a message
- System categorizes the message (greeting, pricing, support, features)
- Analyzes sentiment (positive, negative, neutral)
- Calls OpenAI API if available, otherwise uses predefined responses
- Saves conversation to database
- Returns response to user
- greeting: hello, hi, hey
- pricing: price, cost, pricing
- support: help, support, issue, problem
- features: feature, capability, what can
- default: other queries
When OpenAI is unavailable, the chatbot uses simple predefined responses:
greeting: "Hello! How can I help you today?"
pricing: "Our pricing plans start at $9.99/month..."
support: "I'm here to help! Can you describe the issue?"
features: "Our platform offers mass email sending..."- Add OpenAI API key to
backend/.env:
OPENAI_API_KEY=your_openai_api_key_here- Install dependencies:
cd backend && npm install
cd ../frontend && npm install- Start servers:
# Backend
cd backend && npm run dev
# Frontend
cd frontend && npm run dev- Visit
/chatbotor use the chat widget
POST /api/chatbot/message- Send message, get responseGET /api/chatbot/history/:userId- Get chat historyPOST /api/chatbot/test- Test chatbot
Backend:
services/chatbotService.js- Core AI logiccontrollers/chatbotController.js- API handlersroutes/chatbotRoutes.js- Routesmodels/Message.js- Database schema
Frontend:
pages/Chatbot.jsx- Chat interfacecomponents/ChatbotWidget.jsx- Embeddable widget