{
  "openapi": "3.1.0",
  "info": {
    "title": "Linkora Bot OpenAPI",
    "version": "2.0.0",
    "description": "Linkora 机器人开放平台 HTTP API 规范。支持交互式内联按钮、群成员状态查询、消息发送/编辑/撤回/置顶、群管禁言/解禁/移出/解封、Webhook 推送与 getUpdates 轮询。"
  },
  "servers": [
    {
      "url": "https://bot.linkora.chat",
      "description": "Linkora 机器人专属 API 网关（推荐）"
    },
    {
      "url": "https://app.linkora.chat",
      "description": "Linkora 主 API 网关（兼容保留）"
    }
  ],
  "security": [
    {
      "BotApiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "BotApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "格式：Authorization: Bot lkb_live_xxxxxxxxxxxxxxxx"
      }
    },
    "schemas": {
      "BotInlineButton": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40,
            "description": "按钮展示文案"
          },
          "callbackData": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "description": "回调按钮数据（点击后向机器人发送 callback_query 事件）"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "description": "外链跳转按钮（仅支持 https:// 或 http://）"
          },
          "copyText": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "description": "一键复制按钮（点击后将内容复制到剪贴板）"
          }
        },
        "description": "每个按钮必须且只能指定 callbackData、url、copyText 三者之一。"
      },
      "BotReplyMarkup": {
        "type": "object",
        "required": [
          "inlineKeyboard"
        ],
        "properties": {
          "inlineKeyboard": {
            "type": "array",
            "maxItems": 8,
            "description": "二维按钮矩阵：最多 8 行，每行 1-4 个按钮，单条消息最多 24 个按钮",
            "items": {
              "type": "array",
              "minItems": 1,
              "maxItems": 4,
              "items": {
                "$ref": "#/components/schemas/BotInlineButton"
              }
            }
          }
        }
      },
      "BotCommand": {
        "type": "object",
        "required": [
          "command",
          "description"
        ],
        "properties": {
          "command": {
            "type": "string",
            "pattern": "^[a-z0-9_]{1,32}$"
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          }
        }
      },
      "SendMessageRequest": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "replyToMessageId": {
            "type": "string",
            "format": "uuid"
          },
          "replyMarkup": {
            "$ref": "#/components/schemas/BotReplyMarkup"
          }
        }
      },
      "EditMessageRequest": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "replyMarkup": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/BotReplyMarkup"
              },
              {
                "type": "null"
              }
            ],
            "description": "传入 null 可移除消息下方的所有内联按钮"
          }
        }
      },
      "GroupMemberStatus": {
        "type": "object",
        "properties": {
          "groupId": {
            "type": "string",
            "format": "uuid"
          },
          "userId": {
            "type": "string",
            "format": "uuid"
          },
          "inGroup": {
            "type": "boolean",
            "description": "此用户当前是否在本群中"
          },
          "status": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "member",
              "restricted",
              "left",
              "kicked"
            ]
          },
          "role": {
            "type": "string",
            "nullable": true,
            "enum": [
              "owner",
              "admin",
              "member",
              null
            ]
          },
          "muted": {
            "type": "boolean"
          },
          "mutedUntil": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "banned": {
            "type": "boolean"
          },
          "joinedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "leftAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      }
    }
  },
  "paths": {
    "/v1/bot/me": {
      "get": {
        "tags": [
          "基础与配置"
        ],
        "summary": "获取当前机器人资料、指令与已绑定群列表",
        "responses": {
          "200": {
            "description": "返回机器人元信息"
          }
        }
      }
    },
    "/v1/bot/commands": {
      "get": {
        "tags": [
          "基础与配置"
        ],
        "summary": "获取机器人斜杠指令列表",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "put": {
        "tags": [
          "基础与配置"
        ],
        "summary": "设置机器人斜杠指令列表（setMyCommands）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "commands"
                ],
                "properties": {
                  "commands": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "$ref": "#/components/schemas/BotCommand"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "基础与配置"
        ],
        "summary": "清空机器人指令列表",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/webhook": {
      "get": {
        "tags": [
          "事件与 Webhook"
        ],
        "summary": "查询 Webhook 配置与投递状态（getWebhookInfo）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "put": {
        "tags": [
          "事件与 Webhook"
        ],
        "summary": "设置或更新 HTTPS Webhook（setWebhook）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "HTTPS Webhook 地址；传空字符串表示关闭 Webhook"
                  },
                  "rotateSecret": {
                    "type": "boolean",
                    "description": "是否同时轮换 HMAC 签名密钥"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "事件与 Webhook"
        ],
        "summary": "关闭 Webhook 推送（deleteWebhook）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/updates": {
      "get": {
        "tags": [
          "事件与 Webhook"
        ],
        "summary": "按游标拉取待处理事件（getUpdates 轮询模式）",
        "parameters": [
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "description": "传入上次 nextOffset 自动确认并清理更早事件"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "返回 updates 列表与 nextOffset"
          }
        }
      }
    },
    "/v1/bot/users/resolve": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "按 @handle 解析用户 UUID 与公开资料",
        "parameters": [
          {
            "name": "handle",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/users/{userId}": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "按 UUID 查询用户公开资料",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "获取群组详情与机器人权限（getChat）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/member-count": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "获取群成员总数（getChatMemberCount）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members/{userIdOrHandle}": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "查询指定用户是否在本群及其角色/禁言/封禁状态（getChatMember）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "userIdOrHandle",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "支持用户 UUID 或 @handle"
          }
        ],
        "responses": {
          "200": {
            "description": "返回成员在群状态",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GroupMemberStatus"
                }
              }
            }
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "分页获取群活跃成员列表",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "role",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "owner",
                "admin",
                "member"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/admins": {
      "get": {
        "tags": [
          "用户与群成员"
        ],
        "summary": "获取群主与全部管理员（getChatAdministrators）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/messages": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "发送群消息（支持引用回复与内联按钮）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendMessageRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "消息已发送"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/messages/{messageId}": {
      "put": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "编辑机器人已发送的群消息文案或内联按钮",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditMessageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "消息已更新"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/messages/{messageId}/recall": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "撤回群消息（自身消息或普通成员违规消息）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/messages/{messageId}/pin": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "置顶群消息（pinChatMessage）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "取消置顶群消息（unpinChatMessage）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/direct/{userId}/messages": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "发送 1v1 私聊消息（支持引用回复与内联按钮）",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendMessageRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/direct/{userId}/messages/{messageId}": {
      "put": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "编辑机器人已发送的私聊消息或按钮",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditMessageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/direct/{userId}/messages/{messageId}/recall": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "撤回机器人自己发送的私聊消息",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/callback-queries/{callbackQueryId}/answer": {
      "post": {
        "tags": [
          "消息与内联按钮"
        ],
        "summary": "应答用户的内联按钮点击（answerCallbackQuery）",
        "parameters": [
          {
            "name": "callbackQueryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 300,
                    "description": "给点击用户的轻提示或弹窗正文"
                  },
                  "showAlert": {
                    "type": "boolean",
                    "default": false,
                    "description": "true 时弹出确认对话框，false 时显示底部轻提示"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 500,
                    "description": "可选附带打开的 HTTPS 链接"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members/{userId}/mute": {
      "post": {
        "tags": [
          "群组管理"
        ],
        "summary": "禁言群成员（restrictChatMember）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "minutes": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 43200,
                    "description": "禁言分钟数；0 表示持续禁言直到解除"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members/{userId}/unmute": {
      "post": {
        "tags": [
          "群组管理"
        ],
        "summary": "立即解除群成员禁言",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members/{userId}/kick": {
      "post": {
        "tags": [
          "群组管理"
        ],
        "summary": "移出群成员（banChatMember）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ban": {
                    "type": "boolean",
                    "default": true,
                    "description": "是否同时封禁禁止再次加入，默认 true"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/groups/{groupId}/members/{userId}/unban": {
      "post": {
        "tags": [
          "群组管理"
        ],
        "summary": "解除群成员封禁（unbanChatMember）",
        "parameters": [
          {
            "name": "groupId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "OK"
          }
        }
      }
    }
  }
}