{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bot.yoyoo.org/schemas/v1/outbound-message-request.schema.json",
  "title": "OutboundMessageRequest",
  "description": "POST /v1/bots/{id}/messages 请求体。开发者主动发送或回复消息至 Matrix。",
  "type": "object",
  "additionalProperties": false,
  "required": ["room_id", "body"],
  "properties": {
    "room_id": {
      "type": "string",
      "pattern": "^![^\\s:]+:[^\\s:]+$",
      "description": "目标 Matrix 房间 ID。通常与入站 CloudEvent subject / data.matrix.room_id 相同。"
    },
    "body": {
      "type": "string",
      "maxLength": 48000,
      "description": "消息正文。超长时平台按 Matrix 与渠道限制分片发送。"
    },
    "msgtype": {
      "type": "string",
      "enum": ["m.text", "m.notice"],
      "default": "m.text",
      "description": "m.text：普通消息；m.notice：系统提示样式（如无打字机效果的状态行）。"
    },
    "format": {
      "type": "string",
      "enum": ["plain", "html"],
      "default": "plain",
      "description": "html 时平台生成 org.matrix.custom.html 与纯文本 fallback。"
    },
    "reply_to": {
      "type": "object",
      "additionalProperties": false,
      "description": "可选。回复指定 Matrix 事件。",
      "properties": {
        "event_id": {
          "type": "string",
          "pattern": "^\\$[^\\s:]+:[^\\s:]+$",
          "description": "被回复的 Matrix event_id。"
        }
      },
      "required": ["event_id"]
    },
    "stream": {
      "type": "object",
      "additionalProperties": false,
      "description": "可选。流式回复：先创建占位消息，再多次 PATCH 更新同一 event。",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false,
          "description": "true 时启用流式；首次发送返回 stream.message_id 供后续 chunk 引用。"
        },
        "finalize": {
          "type": "boolean",
          "default": true,
          "description": "当前请求是否为流式最后一帧。false 时保留「生成中」状态。"
        },
        "message_id": {
          "type": "string",
          "description": "非首帧时必填。平台在首帧响应中返回的 stream.message_id（内部占位 event 句柄）。"
        }
      }
    },
    "idempotency_key": {
      "type": "string",
      "maxLength": 128,
      "description": "可选。幂等键。相同 bot_id + idempotency_key 在 24h 内重复请求返回同一结果，防重试双发。"
    }
  }
}
