"""Communication diagnostic routes. Moved from app.admin_dashboard in v4.7.2. The handlers still reuse legacy helpers to keep this refactor behavior-preserving. """ from fastapi import APIRouter import app.admin_dashboard as legacy from app.admin_dashboard import * # noqa: F401,F403 router = APIRouter() @router.get("/communications", response_class=HTMLResponse) @router.get("/comunicacoes", response_class=HTMLResponse) async def communications_page(status: Optional[str] = None, classification: Optional[str] = None, q: Optional[str] = None, scope: Optional[str] = None): items = list_communications(status=status, classification=classification, q=q, limit=120) if scope == "without_customer": items = [i for i in items if not i.get("customer_id") and str(i.get("direction") or "inbound") == "inbound"] elif scope == "without_opportunity": items = [i for i in items if not i.get("opportunity_id") and str(i.get("direction") or "inbound") == "inbound"] elif scope == "needs_review": items = [i for i in items if str(i.get("status") or "") == "needs_review"] summary = get_communications_summary() rows = "" for item in items: action = classification_action(item.get("classification")) confidence = item.get("confidence") confidence_label = "—" if confidence is None else f"{float(confidence):.2f}" linked = [] if item.get("customer_name"): linked.append(str(item.get("customer_name"))) elif item.get("customer_id"): linked.append("cliente associado") else: linked.append("sem cliente") if item.get("opportunity_title"): linked.append(str(item.get("opportunity_title"))) elif item.get("opportunity_id"): linked.append("oportunidade associada") else: linked.append("sem oportunidade") rows += f"""
| Mensagem | Classificação | Estado / ação sugerida | Cliente / oportunidade |
|---|