{"id":26045055,"url":"https://github.com/blinksta1ker/chatbot","last_synced_at":"2026-05-08T05:52:29.464Z","repository":{"id":280964428,"uuid":"943742791","full_name":"BLinKSta1Ker/Chatbot","owner":"BLinKSta1Ker","description":"Chatbot using Flask","archived":false,"fork":false,"pushed_at":"2025-03-06T08:18:33.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T09:35:44.483Z","etag":null,"topics":["backend","chatbot","flask","openai-api","postman","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BLinKSta1Ker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-06T07:37:35.000Z","updated_at":"2025-03-06T08:27:03.000Z","dependencies_parsed_at":"2025-03-06T09:46:27.362Z","dependency_job_id":null,"html_url":"https://github.com/BLinKSta1Ker/Chatbot","commit_stats":null,"previous_names":["blinksta1ker/chatbot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BLinKSta1Ker%2FChatbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BLinKSta1Ker%2FChatbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BLinKSta1Ker%2FChatbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BLinKSta1Ker%2FChatbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BLinKSta1Ker","download_url":"https://codeload.github.com/BLinKSta1Ker/Chatbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242450656,"owners_count":20130223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","chatbot","flask","openai-api","postman","python"],"created_at":"2025-03-07T19:30:57.436Z","updated_at":"2026-05-08T05:52:29.458Z","avatar_url":"https://github.com/BLinKSta1Ker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chatbot\n\n![Python](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge\u0026logo=python\u0026logoColor=blue)\n![Flask](https://img.shields.io/badge/Flask-000000?style=for-the-badge\u0026logo=flask\u0026logoColor=white)\n![Redis](https://img.shields.io/badge/redis-%23DD0031.svg?\u0026style=for-the-badge\u0026logo=redis\u0026logoColor=white)\n![MongoDB](https://img.shields.io/badge/MongoDB-4EA94B?style=for-the-badge\u0026logo=mongodb\u0026logoColor=white)\n![OpenAI](https://img.shields.io/badge/ChatGPT-74aa9c?style=for-the-badge\u0026logo=openai\u0026logoColor=white)\n![JWT](https://img.shields.io/badge/JWT-000000?style=for-the-badge\u0026logo=JSON%20web%20tokens\u0026logoColor=white)\n![Postman](https://img.shields.io/badge/Postman-FF6C37?style=for-the-badge\u0026logo=Postman\u0026logoColor=white)\n![VSCode](https://img.shields.io/badge/VSCode-0078D4?style=for-the-badge\u0026logo=visual%20studio%20code\u0026logoColor=white)\n![License](https://img.shields.io/badge/MIT-green?style=for-the-badge)\n\n## 🧠 Chatbot API (Flask + OpenAI + MongoDB + Redis)\n\nA secure, rate-limited, JWT-authenticated chatbot API built with Flask. Supports OpenAI integration for conversational AI, user authentication, admin analytics, and chat history management.\n\n## 🚀 Features\n\n- **User Authentication**\n  - Register/Login with JWT\n  - Secure password hashing\n  - Token blacklisting on logout\n  - Rate-limited endpoints\n\n- **Admin Capabilities**\n  - View total users and total chat messages\n  - List all users\n  - Delete specific users\n\n- **AI Chatbot**\n  - Integrates with OpenAI’s GPT-4o-mini\n  - Maintains short-term context using Redis\n  - Persists 30-day chat history in MongoDB\n\n- **Security**\n  - JWT-based access control\n  - Rate limiting to prevent abuse\n  - Input sanitization with `bleach`\n  - Token revocation via Redis\n\n## 🗂 Project Structure\n\n```\nChatbot/\n├── app/\n│   ├── __init__.py         # Flask app factory\n│   ├── admin.py            # Admin routes\n│   ├── auth.py             # Auth routes\n│   ├── chatbot.py          # AI chat logic\n│   ├── config.py           # Environment/config manager\n│   ├── database.py         # Redis and MongoDB connections\n│   ├── routes.py           # Chat routes\n│   └── utils.py            # Input sanitization\n├── models/\n│   └── conversation.py     # Chat history handlers\n├── .env                    # Environment variables\n├── .gitignore              # Ignored files\n├── error.log               # Error logging\n├── readme.md               # You are here\n├── requirements.txt        # Python dependencies\n└── run.py                  # Entry point\n```\n\n## 📦 Setup Instructions\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/BLinKSta1Ker/Chatbot.git\ncd chatbot\n```\n\n### 2. Install Dependencies\n\nCreate a virtual environment (optional but recommended):\n\n```bash\npython3 -m venv venv\nsource venv/bin/activate\n```\n\nThen install:\n\n```bash\npip install -r requirements.txt\n```\n\n### 3. Set Environment Variables\n\nCreate a `.env` file in the root directory:\n\n```\nOPENAI_API_KEY=your_openai_key\nMONGO_URI=mongodb://localhost:27017\nREDIS_HOST=localhost\nREDIS_PORT=6379\nJWT_SECRET_KEY=supersecret\n```\n\n### 4. Run the App\n\n```bash\npython run.py\n```\n\nThe app will be accessible at `http://127.0.0.1:5000/`.\n\n## 📬 API Endpoints\n\n### 🔐 Auth\n\n| Method | Endpoint           | Description               |\n|--------|--------------------|---------------------------|\n| POST   | `/register`        | Register user             |\n| POST   | `/login`           | Login \u0026 get JWT           |\n| POST   | `/logout`          | Revoke token              |\n| POST   | `/register_admin`  | Register an admin user    |\n\n### 🤖 Chat\n\n| Method | Endpoint           | Description               |\n|--------|--------------------|---------------------------|\n| POST   | `/chat`            | Send a message to chatbot |\n| GET    | `/history`         | Get last 30 days of history |\n\n### 👑 Admin\n\n| Method | Endpoint      | Description               |\n|--------|---------------|---------------------------|\n| GET    | `/admin/stats`| View user/chat stats      |\n| GET    | `/admin/users`| List all users            |\n| DELETE | `/admin/delete_user` | Delete user by ID     |\n\n\u003e **Note:** All chat and admin routes require a valid JWT token in the `Authorization` header.\n\n## 🛡 Security Measures\n\n- Passwords hashed with Werkzeug\n- JWT token expiration and blacklist\n- Brute-force protection via `Flask-Limiter`\n- Input sanitization using `bleach`\n\n## 🧹 Maintenance\n\n- Chat messages older than 30 days are auto-deleted on startup via `delete_old_messages()`.\n\n## 📖 License\n\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblinksta1ker%2Fchatbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblinksta1ker%2Fchatbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblinksta1ker%2Fchatbot/lists"}