> ## Documentation Index
> Fetch the complete documentation index at: https://docs.botmux.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加机器人

> Registers a new Telegram bot. The token is validated with Telegram before saving. Admin only.



## OpenAPI

````yaml POST /api/bots/add
openapi: 3.1.0
info:
  title: BotMux API
  description: >
    REST API for BotMux — a multi-bot Telegram management and proxy platform.


    All endpoints return JSON. Errors return `{"error": "message"}` with HTTP
    500 (or 400/401/403/404 where applicable).


    **Authentication**: Use a Bearer API key (`Authorization: Bearer bmx_...`)
    or a session cookie obtained via `/api/auth/login`.
  version: 1.0.0
  contact:
    name: BotMux
servers:
  - url: http://localhost:8080
    description: Local development server
security:
  - BearerAuth: []
  - CookieAuth: []
tags:
  - name: Bots
    description: Bot registration, configuration, and health management
  - name: Chats
    description: Tracked chat management
  - name: Messages
    description: Message retrieval, search, and actions
  - name: Users
    description: Chat member management
  - name: Admins
    description: Chat administrator management
  - name: Tags
    description: User tagging and labels
  - name: Routes
    description: Message routing rules between bots
  - name: Analytics
    description: Chat statistics and metrics
  - name: Audit Log
    description: Administrative action history
  - name: Long Polling
    description: Pull-based update delivery (Telegram-compatible)
  - name: Telegram Proxy
    description: >
      Transparent proxy to api.telegram.org with message capture and method
      interception.


      Several Telegram Bot API methods are intercepted by BotMux instead of
      being forwarded:

      - `setWebhook` — configures the bot's backend URL in BotMux and enables
      proxy mode (auto-registration of unknown tokens requires
      `BOTMUX_ALLOW_AUTO_REGISTER=1`)

      - `deleteWebhook` — clears the backend URL and disables proxy mode

      - `getWebhookInfo` — returns BotMux's internal webhook state

      - `getUpdates` — served from BotMux's internal queue when long polling is
      enabled; returns empty for any other known bot to prevent conflict errors

      - `logOut` — returns success without forwarding (prevents token being
      disabled for 10 minutes)

      - `close` — returns success without forwarding (prevents bot instance
      shutdown on Telegram's side)


      A file download endpoint at `/tgapi/file/bot{TOKEN}/{file_path}` is also
      available as a drop-in replacement for Telegram's file download URL.
paths:
  /api/bots/add:
    post:
      tags:
        - Bots
      summary: Add a new bot
      description: >-
        Registers a new Telegram bot. The token is validated with Telegram
        before saving. Admin only.
      operationId: addBot
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BotAddRequest'
            example:
              token: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
              name: My Bot
              manage_enabled: true
              proxy_enabled: false
      responses:
        '200':
          description: Bot created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Bot'
        '400':
          description: Invalid request or token validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Admin role required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    BotAddRequest:
      type: object
      required:
        - token
      properties:
        token:
          type: string
          description: Telegram bot token
        name:
          type: string
          description: Display name for the bot
        manage_enabled:
          type: boolean
          default: false
          description: Enable chat management features
        proxy_enabled:
          type: boolean
          default: false
          description: Enable proxy forwarding to backend_url
        backend_url:
          type: string
          description: Backend URL to receive forwarded updates
        secret_token:
          type: string
          description: Secret token for webhook validation
    Bot:
      type: object
      properties:
        id:
          type: integer
          description: Unique bot ID
        token:
          type: string
          description: Telegram bot token
        name:
          type: string
          description: Display name
        source:
          type: string
          enum:
            - cli
            - web
          description: >-
            Registration source (informational only — both types are
            functionally identical)
        manage_enabled:
          type: boolean
          description: Whether chat management features are active for this bot
        proxy_enabled:
          type: boolean
          description: Whether this bot forwards updates to a backend URL
        backend_url:
          type: string
          description: Backend URL to forward updates to (when proxy_enabled)
        secret_token:
          type: string
          description: Secret token for validating backend webhook requests
        long_poll_enabled:
          type: boolean
          description: Whether the long-poll endpoint buffers updates for this bot
        description:
          type: string
          description: Natural-language description used by the LLM router
        running:
          type: boolean
          description: Whether the bot is currently active (polling or webhook-registered)
        webhook_mode:
          type: boolean
          description: Whether the bot is in webhook mode (not polled by BotMux)
        disabled:
          type: boolean
          description: >-
            Whether the bot is disabled. Disabled bots are stopped and do not
            poll or receive webhook updates.
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message
      required:
        - error
      example:
        error: bot not found
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key with `bmx_` prefix. Obtain via `/api/auth/api-keys`.
    CookieAuth:
      type: apiKey
      in: cookie
      name: session
      description: Session cookie obtained after login via `/api/auth/login`.

````