import asyncio
from datetime import datetime, timedelta
from typing import Any, Dict, List
from smartgraph.tools.duck_memory_toolkit import DuckMemoryToolkit
class RefinedCRMSystem:
def __init__(self):
self.memory = DuckMemoryToolkit("new_crm_database.duckdb")
async def add_customer(self, customer_id: str, name: str, email: str, company: str, created_at: str = None):
customer_data = {
"name": name,
"email": email,
"company": company,
"created_at": created_at or datetime.now().isoformat(),
"last_contact": None,
"notes": [],
"deals": []
}
await self.memory.add_memory(f"customer:{customer_id}", customer_data)
print(f"Added customer: {name} from {company}")
async def update_customer_contact(self, customer_id: str, note: str, contact_time: str = None):
customer = await self.memory.get_memory(f"customer:{customer_id}")
if customer:
customer["last_contact"] = contact_time or datetime.now().isoformat()
customer["notes"].append({"date": customer["last_contact"], "note": note})
await self.memory.add_memory(f"customer:{customer_id}", customer)
print(f"Updated contact info for customer: {customer['name']}")
else:
print(f"Customer with ID {customer_id} not found")
async def search_customers(self, query: str) -> List[Dict[str, Any]]:
results = await self.memory.search_memories(query)
found_customers = []
for result in results:
if result["key"].startswith("customer:"):
customer = result["value"]
found_customers.append(customer)
self._print_customer_info(customer)
return found_customers
# ... (other methods)
async def main():
crm = RefinedCRMSystem()
# Add a customer
await crm.add_customer("001", "John Doe", "john@techcorp.com", "TechCorp")
# Update customer contact
await crm.update_customer_contact("001", "Discussed new project requirements")
# Search for customers
await crm.search_customers("John")
if __name__ == "__main__":
asyncio.run(main())