Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
e972df3
1
Parent(s): 0c028d8
fix: Escalation check method in webhook.py (AttributeError)
Browse files- backend/app/api/webhook.py +16 -9
backend/app/api/webhook.py
CHANGED
|
@@ -2283,24 +2283,31 @@ async def process_background_ai_tasks(
|
|
| 2283 |
for msg in conversation_history[-10:]:
|
| 2284 |
esc_history.append({"sender_type": msg.sender_type, "content": msg.content})
|
| 2285 |
|
| 2286 |
-
|
| 2287 |
-
|
| 2288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2289 |
conversation_history=esc_history,
|
| 2290 |
-
|
|
|
|
|
|
|
| 2291 |
)
|
| 2292 |
|
| 2293 |
-
if escalation_result.
|
| 2294 |
logger.info(f"🚨 Escalation triggered in background: {escalation_result.reason}")
|
| 2295 |
lead.needs_attention = True
|
| 2296 |
lead.escalation_reason = escalation_result.reason
|
| 2297 |
session.add(lead)
|
| 2298 |
await session.commit()
|
| 2299 |
|
| 2300 |
-
# Notify Manager
|
| 2301 |
-
|
| 2302 |
-
await notification_service.notify_manager_escalation(
|
| 2303 |
-
session=session,
|
| 2304 |
lead_id=str(lead.id),
|
| 2305 |
lead_name=lead.name or "Unknown",
|
| 2306 |
reason=escalation_result.reason,
|
|
|
|
| 2283 |
for msg in conversation_history[-10:]:
|
| 2284 |
esc_history.append({"sender_type": msg.sender_type, "content": msg.content})
|
| 2285 |
|
| 2286 |
+
# Get last AI response
|
| 2287 |
+
last_ai_response = ""
|
| 2288 |
+
if conversation_history:
|
| 2289 |
+
last_msg = conversation_history[-1]
|
| 2290 |
+
if last_msg.sender_type == 'ai':
|
| 2291 |
+
last_ai_response = last_msg.content
|
| 2292 |
+
|
| 2293 |
+
escalation_result = await escalation_service.analyze_message_smart(
|
| 2294 |
+
user_message=user_message_text,
|
| 2295 |
+
ai_response=last_ai_response,
|
| 2296 |
conversation_history=esc_history,
|
| 2297 |
+
heat_score=lead.heat_score or 0,
|
| 2298 |
+
business_type=getattr(tenant, 'business_type', ''),
|
| 2299 |
+
current_stage=None
|
| 2300 |
)
|
| 2301 |
|
| 2302 |
+
if escalation_result.should_escalate:
|
| 2303 |
logger.info(f"🚨 Escalation triggered in background: {escalation_result.reason}")
|
| 2304 |
lead.needs_attention = True
|
| 2305 |
lead.escalation_reason = escalation_result.reason
|
| 2306 |
session.add(lead)
|
| 2307 |
await session.commit()
|
| 2308 |
|
| 2309 |
+
# Notify Manager using EscalationService directly
|
| 2310 |
+
await escalation_service.send_escalation_notification(
|
|
|
|
|
|
|
| 2311 |
lead_id=str(lead.id),
|
| 2312 |
lead_name=lead.name or "Unknown",
|
| 2313 |
reason=escalation_result.reason,
|