{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mojeeb-app/json-schema/mojeeb-app-message-schema.json",
  "title": "Message",
  "description": "A message in a conversation.",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mojeeb-app-openapi.yaml#/components/schemas/Message",
  "type": "object",
  "required": [
    "id",
    "conversation_id",
    "sender",
    "sender_user_id",
    "type",
    "text",
    "attachments",
    "status",
    "failure_reason",
    "interaction",
    "reply_to_message_id",
    "template",
    "created_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "conversation_id": {
      "type": "string",
      "format": "uuid"
    },
    "sender": {
      "type": "string",
      "description": "`customer`, `ai`, `user` (a teammate, or a key writing as its creator, as in a comment's `hidden_by`), `automation` (Mojeeb for the business: a broadcast, a `/v1/whatsapp` send) or `system`; new values may appear."
    },
    "sender_user_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "For a `user` message, the teammate who wrote it (for a key's reply, the person who created the key); null for a reply typed in the WhatsApp Business app or Meta's inbox."
    },
    "type": {
      "type": "string",
      "description": "`text`, `image`, `audio`, `video`, `document` or `template`; new values may appear."
    },
    "text": {
      "type": [
        "string",
        "null"
      ],
      "description": "What it says; null for media without a caption. Written by the customer when `sender` is `customer`."
    },
    "attachments": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type",
          "url",
          "content_type",
          "size",
          "file_name",
          "duration_seconds",
          "transcript"
        ],
        "properties": {
          "type": {
            "type": "string",
            "description": "`image`, `audio`, `video`, `document` or `sticker`."
          },
          "url": {
            "type": "string",
            "description": "A link to read it, valid for about 24 hours."
          },
          "content_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "size": {
            "type": [
              "integer",
              "null"
            ],
            "description": "In bytes."
          },
          "file_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "description": "For audio and video."
          },
          "transcript": {
            "type": [
              "string",
              "null"
            ],
            "description": "A voice note's transcript",
            "when Mojeeb made one.": null
          }
        }
      }
    },
    "status": {
      "type": [
        "string",
        "null"
      ],
      "description": "For a message sent to the customer: `queued` (not sent yet), `sent`, `delivered`, `read` or `failed`. Facebook and Instagram skip `sent` for messages Mojeeb sends: they read `delivered` once sent (a reply typed in Meta's inbox starts at `sent`). Null for the customer's own messages."
    },
    "failure_reason": {
      "type": [
        "string",
        "null"
      ],
      "description": "Why it failed, when `status` is `failed`: the same stable category `getWhatsAppMessageStatus` reports for its `failure_reason` (for example `RecipientUnreachable` when the 24-hour window had closed). Forever-additive: branch with a default."
    },
    "interaction": {
      "type": [
        "object",
        "null"
      ],
      "description": "For a customer's message that answered a button or a list: what they tapped. Null otherwise.",
      "required": [
        "type",
        "id",
        "payload",
        "title"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "`quick_reply` (a WhatsApp template's button), `button_reply` or `list_reply` (an interactive message's button or list row) or `postback` (a Messenger or Instagram button); new values may appear."
        },
        "id": {
          "type": [
            "string",
            "null"
          ],
          "description": "The id the business gave the interactive button or list row."
        },
        "payload": {
          "type": [
            "string",
            "null"
          ],
          "description": "The `quick_reply_payload` the template's button was sent with; for a button sent without one, WhatsApp repeats the label."
        },
        "title": {
          "type": [
            "string",
            "null"
          ],
          "description": "The label the customer saw."
        }
      }
    },
    "reply_to_message_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "The `id` of the message in this conversation that this one answers: the template whose button the customer tapped, or a message they swiped to reply to. Null when it answers none, or when the message it answers isn't in Mojeeb (sent from the WhatsApp Business app, for example). WhatsApp only; replies received before this field was added don't carry it."
    },
    "template": {
      "type": [
        "object",
        "null"
      ],
      "description": "For a WhatsApp template sent from Mojeeb (the API, a broadcast or the dashboard): the template it was sent from. Null otherwise, and for templates sent before this field was added.",
      "required": [
        "id",
        "name",
        "language"
      ],
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Meta's id for the template's language version: the `template_id` the template endpoints take. Null when it wasn't known at send time."
        },
        "name": {
          "type": "string"
        },
        "language": {
          "type": "string",
          "description": "The language code it was sent in, for example `it` or `en_US`."
        }
      }
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  }
}