File size: 1,176 Bytes
5749e42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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())