{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/osis-co/json-schema/osis-co-message-schema.json",
  "title": "Message",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/osis-co-openapi.json#/components/schemas/Message",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "body": {
      "type": "string"
    },
    "direction": {
      "type": "string",
      "enum": [
        "outbound",
        "inbound"
      ]
    },
    "conversation_id": {
      "type": "string"
    },
    "reply_to_message_id": {
      "type": "string",
      "description": "The ID of the message this replies to, if it's in this conversation."
    },
    "thread_root_message_id": {
      "type": "string",
      "description": "The first message in this thread."
    },
    "channel": {
      "type": "string",
      "enum": [
        "sms",
        "imessage",
        "rcs",
        "whatsapp"
      ]
    },
    "status": {
      "type": "string"
    },
    "contact_id": {
      "type": "string"
    },
    "line_id": {
      "type": "string",
      "description": "Line ID when available."
    },
    "line_e164": {
      "type": "string",
      "description": "Your number in this conversation: the number that received the message, or the number you sent from."
    },
    "to": {
      "type": "string"
    },
    "read_at": {
      "type": "string",
      "format": "date-time",
      "description": "The native read time when a read receipt is available. For one-to-one iMessage and RCS, the recipient must have read receipts on. Never available for SMS; absence does not mean unread."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "audience": {
      "type": "string",
      "enum": [
        "direct",
        "shared"
      ],
      "description": "Whether the message is in a group conversation or a one-on-one conversation."
    },
    "author": {
      "type": "object",
      "description": "Who sent the message. Display names aren't verified.",
      "properties": {
        "contact_id": {
          "type": "string"
        },
        "external_id": {
          "type": "string"
        },
        "display_name": {
          "type": "string"
        }
      },
      "required": [
        "contact_id",
        "external_id"
      ]
    },
    "reply_to_provider_message_id": {
      "type": "string",
      "description": "Another ID for the message this replies to, when available."
    },
    "thread_originator_guid": {
      "type": "string",
      "description": "Another ID for the first message in the thread, when available."
    },
    "attachments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/InboundAttachment"
      },
      "description": "Files someone sent you. If a message is only files, body is empty."
    },
    "unsent_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the unsend was confirmed. The original text and delivery history are kept."
    }
  },
  "$defs": {
    "InboundAttachment": {
      "type": "object",
      "required": [
        "filename",
        "content_type",
        "mediaType"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "filename": {
          "type": "string"
        },
        "content_type": {
          "type": "string"
        },
        "mediaType": {
          "type": "string"
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "transcription": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Where to download the file. Needs an API key with comms_read from the same workspace and line."
        }
      }
    }
  }
}