{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/envoisms-ma/json-schema/envoisms-ma-message-record-schema.json",
  "title": "MessageRecord",
  "description": "A stored message as returned by GET /messages/{id}. The metadata object provided at send time is not echoed here; it travels in DLR webhooks.",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/envoisms-ma-api-openapi.json#/components/schemas/MessageRecord",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "campaign_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "to": {
      "type": "string"
    },
    "channel": {
      "type": "string",
      "enum": [
        "sms",
        "whatsapp",
        "telegram",
        "voice",
        "rcs"
      ]
    },
    "body": {
      "type": "string"
    },
    "sender_id": {
      "type": "string"
    },
    "unicode": {
      "type": "integer",
      "description": "1 when the body required the UCS-2 alphabet (Arabic etc.), 0 for GSM-7"
    },
    "segments": {
      "type": "integer"
    },
    "status": {
      "type": "string",
      "enum": [
        "queued",
        "sent",
        "delivered",
        "failed",
        "undeliverable",
        "unconfirmed"
      ],
      "description": "unconfirmed = the network accepted the message but never reported a final outcome within the reporting window; a delivery receipt arriving later still replaces it."
    },
    "error_code": {
      "type": [
        "string",
        "null"
      ],
      "description": "Set on failed/undeliverable messages. A short diagnostic key: DLR_<network status> when the failure came from a delivery report (e.g. DLR_REJECTD, DLR_EXPIRED, DLR_UNDELIV), GATEWAY_* for a failure on the EnvoiSMS routing side before the network was reached, ENVOISMS_* for other routing diagnostics, META_* for a WhatsApp refusal (see \"WhatsApp failure codes\" in the API description). Treat unknown values as a generic terminal failure — new keys may appear."
    },
    "error_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "Human-readable failure reason in English, set together with error_code. When the network gave no reason, this reads \"The destination network did not deliver this message and gave no reason.\" Display text — do not parse it programmatically; branch on status and error_code instead."
    },
    "cost_eur": {
      "type": "number"
    },
    "cost_mad": {
      "type": "number"
    },
    "scheduled_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "sent_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "delivered_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "read_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Timestamp when the recipient opened and read the message (WhatsApp blue checkmark)"
    },
    "failed_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "operator": {
      "type": [
        "string",
        "null"
      ],
      "description": "Resolved destination network for Moroccan numbers (Maroc Telecom, Orange, Inwi, Autre); best-effort elsewhere."
    },
    "sandbox": {
      "type": "integer",
      "description": "1 when the message was created by an env_test_ sandbox key"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  }
}