This project is a dynamic chatbot that uses OpenAI to ask unique, non-personal questions to the user and records their responses. The chatbot frontend is built with ReactJS, the backend with ExpressJS, and MongoDB is used to store the conversations. The application dynamically generates questions using OpenAI's API and ensures that no duplicate questions are asked during a session.
- Dynamic Question Generation: The chatbot uses OpenAI to generate unique, non-personal questions.
- Session Management: Each user session is tracked with a unique identifier, and both questions and answers are stored.
- Answer Storage: User responses are saved in MongoDB for future reference.
- Restartable Sessions: After a session ends, users can start a new session with fresh questions.
- Real-time Interaction: Smooth UI interaction, including typing indicators and scroll-to-bottom functionality.
- Frontend: ReactJS
- Backend: ExpressJS
- Database: MongoDB
- API Integration: OpenAI API
- UI/UX: Custom CSS for chat UI and smooth interactions
Before starting the project, make sure to create the .env
file in the backend
directory and set up the necessary environment variables. This is critical for the backend to function properly.
- Create a
.env
file in thebackend
directory. - Add the following environment variables:
MONGO_URI=mongodb://localhost:27017/Chatbot OPENAI_API_KEY=your-openai-api-key
- Node.js (v14.x or higher)
- MongoDB (local or cloud instance)
- OpenAI API key
git clone git@github.com:ozanozkayatr/bolt-chat.git
cd chatbot-app
-
Navigate to the
backend
folder:cd backend
-
Install the necessary dependencies:
npm install
-
Make sure the
.env
file is configured correctly as described above. -
Start the backend server:
node index.js
The backend server will be running on
http://localhost:3001
.
-
Navigate to the
frontend
folder:cd ../frontend
-
Install the necessary dependencies:
npm install
-
Start the frontend application:
npm start
The frontend will be running on
http://localhost:3000
.
- Start a Session: The chatbot begins with a new session, where it asks a series of dynamically generated questions using OpenAI.
- Answer Questions: Respond to each question, and your answers will be saved in MongoDB.
- End a Session: After answering all the questions, a closing message will appear, and you'll have the option to start a new session.
├── backend
│ ├── index.js # Entry point for the backend
│ ├── models
│ │ └── Session.js # MongoDB schema for session data
│ ├── routes
│ │ └── chat.js # Routes for handling chat requests
│ └── openai.js # OpenAI integration logic
├── frontend
│ ├── src
│ │ ├── components
│ │ │ ├── ChatWindow.js # Chat window component
│ │ │ ├── InputForm.js # Input form for user responses
│ │ │ └── MessageCard.js # Message display component
│ │ ├── App.js # Main React application
│ │ └── index.js # Entry point for the frontend
│ └── public # Static files (HTML, favicon, etc.)
-
POST /chat/randomQuestion
Generates a unique, dynamic question using OpenAI's API and returns it. -
POST /chat/answer
Saves the user's response to the corresponding question in the session.