Spaces:
Sleeping
Sleeping
| # add_chatbot_test.py | |
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from app.config import settings | |
| import asyncio | |
| # Connect to MongoDB | |
| client = AsyncIOMotorClient(settings.mongo_uri) | |
| db = client[settings.mongo_db_name] | |
| users = db["Users"] | |
| # Replace with actual user ID | |
| USER_ID = "6629596a-a57e-41b4-8b07-d53aa159385a" | |
| # Chatbot to add | |
| new_chatbot = { | |
| "chatbot_id": "0167ee52-abab-51f4-ad16-be584089ca96", | |
| "chatbot_name": "Test Chatbot", | |
| "company_name": "Test Company", | |
| "company_id": "e3cd56a7-affc-5045-963d-dd69efbea3e6" | |
| } | |
| async def add_chatbot(): | |
| user = await users.find_one({"_id": USER_ID}) | |
| if not user: | |
| print("User not found") | |
| return | |
| chatbots = user.get("chatbots", []) | |
| # Avoid duplicates | |
| if any(c["chatbot_id"] == new_chatbot["chatbot_id"] for c in chatbots): | |
| print("Chatbot already exists for this user") | |
| return | |
| chatbots.append(new_chatbot) | |
| await users.update_one( | |
| {"_id": USER_ID}, | |
| {"$set": {"chatbots": chatbots}} | |
| ) | |
| print("Chatbot added successfully") | |
| print("Updated chatbots:", chatbots) | |
| if __name__ == "__main__": | |
| asyncio.run(add_chatbot()) | |