feat: Implement Trading Twins Autopilot with Teams integration and फैक्टर-3 overbooking logic [31988f42]
This commit is contained in:
@@ -9,6 +9,13 @@ sys.path.append(os.path.dirname(__file__))
|
||||
from db import get_leads
|
||||
from enrich import refresh_ce_data
|
||||
|
||||
# Import our new Trading Twins Orchestrator
|
||||
try:
|
||||
from trading_twins.orchestrator import TradingTwinsOrchestrator
|
||||
except ImportError:
|
||||
# Fallback for dev environment or missing dependencies
|
||||
TradingTwinsOrchestrator = None
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger("lead-monitor")
|
||||
@@ -16,6 +23,9 @@ logger = logging.getLogger("lead-monitor")
|
||||
def run_monitor():
|
||||
logger.info("Starting Lead Monitor (Polling CE for updates)...")
|
||||
|
||||
# Initialize Orchestrator once
|
||||
orchestrator = TradingTwinsOrchestrator() if TradingTwinsOrchestrator else None
|
||||
|
||||
while True:
|
||||
try:
|
||||
leads = get_leads()
|
||||
@@ -44,7 +54,24 @@ def run_monitor():
|
||||
new_vertical = new_data.get('industry_ai') or new_data.get('vertical')
|
||||
if new_vertical and new_vertical != 'None':
|
||||
logger.info(f" [SUCCESS] Analysis finished for {lead['company_name']}: {new_vertical}")
|
||||
# Optional: Here we could trigger the Auto-Reply generation in the future
|
||||
|
||||
# Trigger Trading Twins Process
|
||||
if orchestrator:
|
||||
logger.info(f" [ACTION] Triggering Trading Twins Orchestrator for {lead['company_name']}...")
|
||||
try:
|
||||
# Extract contact details safely
|
||||
email = lead.get('email')
|
||||
name = lead.get('contact_name', 'Interessent')
|
||||
company = lead.get('company_name', 'Ihre Firma')
|
||||
|
||||
if email:
|
||||
orchestrator.process_lead(email, name, company)
|
||||
else:
|
||||
logger.warning(f" [SKIP] No email address found for lead {lead['id']}")
|
||||
except Exception as e:
|
||||
logger.error(f" [ERROR] Failed to trigger orchestrator: {e}")
|
||||
else:
|
||||
logger.warning(" [SKIP] Orchestrator not available (Import Error)")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Monitor error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user