{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://calligence.ai/docs/webhooks/schemas/call.analyzed/v1.json",
  "title": "call.analyzed",
  "description": "Cuando termina el análisis de la llamada: el veredicto, el resumen, los datos extraídos y la próxima llamada. Solo cuando el análisis se completa; si falla, se reintenta y el evento sale con el intento que lo completa. Una llamada sin agente que la analice también lo emite, con outcome, summary, extracted y next_call_at a null. Una vez por llamada.",
  "$defs": {
    "AgentRef": {
      "properties": {
        "type": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Type"
        }
      },
      "required": [
        "type"
      ],
      "title": "AgentRef",
      "type": "object"
    },
    "CallRef": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "integer"
        },
        "direction": {
          "examples": [
            "outbound",
            "inbound"
          ],
          "type": "string",
          "title": "Direction"
        },
        "status": {
          "examples": [
            "initiated",
            "completed",
            "failed"
          ],
          "type": "string",
          "title": "Status"
        },
        "attempt_index": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Attempt Index"
        },
        "started_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Started At"
        },
        "ended_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ended At"
        },
        "duration_s": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Duration S"
        },
        "from_number": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "From Number"
        },
        "to_number": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "To Number"
        }
      },
      "required": [
        "id",
        "direction",
        "status",
        "attempt_index",
        "started_at",
        "ended_at",
        "duration_s",
        "from_number",
        "to_number"
      ],
      "title": "CallRef",
      "type": "object"
    },
    "CampaignRef": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "integer"
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Name"
        }
      },
      "required": [
        "id",
        "name"
      ],
      "title": "CampaignRef",
      "type": "object"
    },
    "CustomerRef": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "integer"
        },
        "external_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "External Id"
        },
        "phone": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Phone"
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Name"
        }
      },
      "required": [
        "id",
        "external_id",
        "phone",
        "name"
      ],
      "title": "CustomerRef",
      "type": "object"
    },
    "LeadRef": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "integer"
        },
        "status": {
          "examples": [
            "PENDIENTE",
            "EXITO",
            "INVALIDO",
            "NO_INTERESADO",
            "TRABAJADO_EXTERNO"
          ],
          "type": "string",
          "title": "Status"
        },
        "status_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Status Reason"
        },
        "product_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Product Name"
        },
        "product_code": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Product Code"
        }
      },
      "required": [
        "id",
        "status",
        "status_reason",
        "product_name",
        "product_code"
      ],
      "title": "LeadRef",
      "type": "object"
    },
    "Outcome": {
      "properties": {
        "lead_status": {
          "anyOf": [
            {
              "examples": [
                "PENDIENTE",
                "EXITO",
                "INVALIDO",
                "NO_INTERESADO",
                "TRABAJADO_EXTERNO"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Lead Status"
        },
        "reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Reason"
        },
        "intent": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Intent"
        }
      },
      "required": [
        "lead_status",
        "reason",
        "intent"
      ],
      "title": "Outcome",
      "type": "object"
    },
    "TranscriptTurn": {
      "properties": {
        "role": {
          "examples": [
            "agent",
            "user"
          ],
          "type": "string",
          "title": "Role"
        },
        "text": {
          "title": "Text",
          "type": "string"
        }
      },
      "required": [
        "role",
        "text"
      ],
      "title": "TranscriptTurn",
      "type": "object"
    }
  },
  "properties": {
    "call": {
      "$ref": "#/$defs/CallRef"
    },
    "lead": {
      "anyOf": [
        {
          "$ref": "#/$defs/LeadRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "customer": {
      "anyOf": [
        {
          "$ref": "#/$defs/CustomerRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "campaign": {
      "anyOf": [
        {
          "$ref": "#/$defs/CampaignRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "agent": {
      "$ref": "#/$defs/AgentRef"
    },
    "outcome": {
      "anyOf": [
        {
          "$ref": "#/$defs/Outcome"
        },
        {
          "type": "null"
        }
      ]
    },
    "summary": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Summary"
    },
    "extracted": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "title": "Extracted"
    },
    "next_call_at": {
      "anyOf": [
        {
          "format": "date-time",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Next Call At"
    },
    "transcript": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/TranscriptTurn"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Transcript"
    },
    "transcript_truncated": {
      "title": "Transcript Truncated",
      "type": "boolean"
    }
  },
  "required": [
    "call",
    "lead",
    "customer",
    "campaign",
    "agent",
    "outcome",
    "summary",
    "extracted",
    "next_call_at",
    "transcript",
    "transcript_truncated"
  ],
  "type": "object"
}
