{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://calligence.ai/docs/webhooks/schemas/whatsapp.message.status_updated/v1.json",
  "title": "whatsapp.message.status_updated",
  "description": "Cuando cambia el estado de entrega de un mensaje enviado (entregado, leído, fallido…) o cuando un envío falla. Una vez por mensaje y estado.",
  "$defs": {
    "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"
    },
    "StatusMessage": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "integer"
        },
        "author": {
          "examples": [
            "template",
            "precall_notice",
            "ai",
            "operator"
          ],
          "type": "string",
          "title": "Author"
        },
        "sender_number": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Sender Number"
        },
        "customer_number": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Customer Number"
        }
      },
      "required": [
        "id",
        "author",
        "sender_number",
        "customer_number"
      ],
      "title": "StatusMessage",
      "type": "object"
    }
  },
  "properties": {
    "customer": {
      "anyOf": [
        {
          "$ref": "#/$defs/CustomerRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "lead": {
      "anyOf": [
        {
          "$ref": "#/$defs/LeadRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "campaign": {
      "anyOf": [
        {
          "$ref": "#/$defs/CampaignRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "message": {
      "$ref": "#/$defs/StatusMessage"
    },
    "status": {
      "examples": [
        "sent",
        "delivered",
        "read",
        "failed",
        "undelivered"
      ],
      "type": "string",
      "title": "Status"
    },
    "error": {
      "anyOf": [
        {
          "examples": [
            "rejected",
            "not_sent",
            "outcome_unknown",
            "delivery_failed"
          ],
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error"
    },
    "updated_at": {
      "format": "date-time",
      "title": "Updated At",
      "type": "string"
    }
  },
  "required": [
    "customer",
    "lead",
    "campaign",
    "message",
    "status",
    "error",
    "updated_at"
  ],
  "type": "object"
}
