POST /api/externalAPIs/public/docAnalyzer/batchAnalyzeDialogue

Analisa várias conversas em lote usando um schema JSON e instruções, persistindo os resultados em public.conversations_reports.

Autenticação: Authorization: Bearer $TOKEN

cURL — por UUID

curl -X POST "$BASE_URL/api/externalAPIs/public/docAnalyzer/batchAnalyzeDialogue" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "550e8400-e29b-41d4-a716-446655440000",
    "schema": {
      "type": "object",
      "properties": {
        "sentimento": {
          "type": "string",
          "enum": ["positivo", "neutro", "negativo"]
        }
      }
    },
    "instructions": "Identifique o sentimento do cliente",
    "intervalMs": 200
  }'

cURL — por SELECT

curl -X POST "$BASE_URL/api/externalAPIs/public/docAnalyzer/batchAnalyzeDialogue" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "SELECT id FROM conversations WHERE created_at > '\''2024-11-01'\'' LIMIT 10",
    "schema": {
      "type": "object",
      "properties": {
        "tema": { "type": "string" }
      }
    },
    "instructions": "Extraia o tema principal"
  }'

Parâmetros

  • input: String — UUID único ou query SELECT que retorna id de conversations
  • schema: Object — JSON Schema do objeto de saída
  • instructions: String — Instruções de análise para o LLM
  • model: String (opcional) — Modelo LLM; padrão: gpt-4o-mini
  • intervalMs: Number (opcional) — Intervalo entre processamentos; padrão: 200
  • globalData: Object (opcional) — Objeto de contexto compartilhado

Resposta (exemplo)

{
  "data": {
    "total": 10,
    "processed": 10,
    "succeeded": 9,
    "failed": 1,
    "elapsedSeconds": 12.45,
    "results": [
      {
        "conversationId": "550e8400-e29b-41d4-a716-446655440000",
        "success": true,
        "metrics": { "elapsedMs": 2340 }
      }
    ]
  },
  "error": null
}

Segurança

  • ✅ Apenas queries SELECT são permitidas
  • ✅ Validação de UUID de entrada
  • ✅ Autenticação via middleware
  • ✅ Logs de execução

Consultar resultados

-- Buscar análises de uma conversa
SELECT * FROM conversations_reports 
WHERE conversation_id = '550e8400-e29b-41d4-a716-446655440000';

-- Análises recentes (últimas 24h)
SELECT * FROM conversations_reports 
WHERE created_at > NOW() - INTERVAL '1 day'
ORDER BY created_at DESC;

-- Agregar por sentimento (exemplo de schema de sentimento)
SELECT 
  analysis->>'sentimento' AS sentimento,
  COUNT(*) AS quantidade
FROM conversations_reports
GROUP BY analysis->>'sentimento';