{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/microsoft-azure-communication-services/json-schema/microsoft-azure-communication-services-chat-message-schema.json",
  "title": "ChatMessage",
  "description": "Chat message.",
  "x-generated": "2026-11-05",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/microsoft-azure-communication-services-chat-api-openapi.yml#/components/schemas/ChatMessage",
  "required": [
    "createdOn",
    "id",
    "sequenceId",
    "type",
    "version"
  ],
  "type": "object",
  "properties": {
    "id": {
      "description": "The id of the chat message. This id is server generated.",
      "type": "string"
    },
    "type": {
      "$ref": "#/$defs/ChatMessageType"
    },
    "sequenceId": {
      "description": "Sequence of the chat message in the conversation.",
      "type": "string"
    },
    "version": {
      "description": "Version of the chat message.",
      "type": "string"
    },
    "content": {
      "$ref": "#/$defs/ChatMessageContent"
    },
    "senderDisplayName": {
      "description": "The display name of the chat message sender. This property is used to populate sender name for push notifications.",
      "type": "string"
    },
    "createdOn": {
      "format": "date-time",
      "description": "The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.",
      "type": "string"
    },
    "senderCommunicationIdentifier": {
      "$ref": "#/$defs/CommunicationIdentifierModel"
    },
    "deletedOn": {
      "format": "date-time",
      "description": "The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.",
      "type": "string"
    },
    "editedOn": {
      "format": "date-time",
      "description": "The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.",
      "type": "string"
    },
    "metadata": {
      "description": "Message metadata.",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  },
  "$defs": {
    "ChatAttachment": {
      "description": "An attachment in a chat message.",
      "required": [
        "id",
        "attachmentType"
      ],
      "type": "object",
      "properties": {
        "id": {
          "description": "Id of the attachment",
          "type": "string"
        },
        "attachmentType": {
          "$ref": "#/$defs/ChatAttachmentType"
        },
        "name": {
          "description": "The name of the attachment content.",
          "type": "string"
        },
        "url": {
          "description": "The URL where the attachment can be downloaded",
          "type": "string",
          "format": "uri"
        },
        "previewUrl": {
          "description": "The URL where the preview of attachment can be downloaded",
          "type": "string",
          "format": "uri"
        }
      }
    },
    "ChatAttachmentType": {
      "description": "The type of attachment.",
      "enum": [
        "image",
        "file"
      ],
      "type": "string",
      "x-ms-enum": {
        "name": "ChatAttachmentType",
        "modelAsString": true
      }
    },
    "ChatMessageContent": {
      "description": "Content of a chat message.",
      "type": "object",
      "properties": {
        "message": {
          "description": "Chat message content for messages of types text or html.",
          "type": "string"
        },
        "topic": {
          "description": "Chat message content for messages of type topicUpdated.",
          "type": "string"
        },
        "participants": {
          "description": "Chat message content for messages of types participantAdded or participantRemoved.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/ChatParticipant"
          }
        },
        "attachments": {
          "description": "List of attachments for this message",
          "type": "array",
          "items": {
            "$ref": "#/$defs/ChatAttachment"
          }
        },
        "initiatorCommunicationIdentifier": {
          "$ref": "#/$defs/CommunicationIdentifierModel"
        }
      }
    },
    "ChatMessageType": {
      "description": "The chat message type.",
      "enum": [
        "text",
        "html",
        "topicUpdated",
        "participantAdded",
        "participantRemoved"
      ],
      "type": "string",
      "x-ms-enum": {
        "name": "ChatMessageType",
        "modelAsString": true
      }
    },
    "ChatParticipant": {
      "description": "A participant of the chat thread.",
      "required": [
        "communicationIdentifier"
      ],
      "type": "object",
      "properties": {
        "communicationIdentifier": {
          "$ref": "#/$defs/CommunicationIdentifierModel"
        },
        "displayName": {
          "description": "Display name for the chat participant.",
          "type": "string"
        },
        "shareHistoryTime": {
          "format": "date-time",
          "description": "Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.",
          "type": "string"
        },
        "metadata": {
          "description": "Contextual metadata for the chat participant. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      }
    },
    "CommunicationIdentifierModel": {
      "$ref": "../../../Common/stable/2025-06-30/common.json#/components/schemas/CommunicationIdentifierModel"
    }
  }
}