# 通过机器人发送消息

Source: https://langbot.app/docs/ja/api-reference/bots/%E9%80%9A%E8%BF%87%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF

## POST /api/v1/platform/bots/{bot_uuid}/send_message

通过指定的机器人向目标发送消息。仅支持 API Key 认证。

Authentication (OpenAPI security alternatives; OR between entries, AND within each entry): [{"ApiKeyAuth":[]}]. See components.securitySchemes below for header names, schemes and scopes.

Servers: http://localhost:5300. Use your own LangBot instance, not the documentation host.

[Complete ja OpenAPI specification](https://langbot.app/docs/openapi/service-api-ja.json)

## Operation contract

The OpenAPI subset below preserves path/operation parameters, request bodies, response codes, media types, examples and schemas. All referenced components are included transitively; resolve local JSON pointers against this document. The operation is preserved verbatim, including security overrides.

```json
{
  "openapi": "3.0.3",
  "info": {
    "title": "LangBot Service API",
    "description": "LangBot external service API documentation. These endpoints support API Key authentication for programmatic access to LangBot resources.\n\n**Authentication:**\n- User Token (via `Authorization: Bearer <token>`)\n- API Key (via `X-API-Key: <key>` or `Authorization: Bearer <key>`)\n\nAll endpoints in this document support both authentication methods unless otherwise noted.\n",
    "version": "4.9.5",
    "contact": {
      "name": "LangBot",
      "url": "https://langbot.app"
    },
    "license": {
      "name": "AGPL-3.0",
      "url": "https://github.com/langbot-app/LangBot/blob/master/LICENSE"
    }
  },
  "servers": [
    {
      "url": "http://localhost:5300",
      "description": "Local development server"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/v1/platform/bots/{bot_uuid}/send_message": {
      "post": {
        "tags": [
          "Bots"
        ],
        "summary": "通过机器人发送消息",
        "description": "通过指定的机器人向目标发送消息。仅支持 API Key 认证。",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "bot_uuid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "target_type",
                  "target_id",
                  "message_chain"
                ],
                "properties": {
                  "target_type": {
                    "type": "string",
                    "enum": [
                      "person",
                      "group"
                    ],
                    "description": "目标类型"
                  },
                  "target_id": {
                    "type": "string",
                    "description": "目标 ID（用户 ID 或群组 ID）"
                  },
                  "message_chain": {
                    "type": "array",
                    "description": "消息链",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "Plain",
                            "Image",
                            "At",
                            "Voice"
                          ],
                          "description": "消息元素类型"
                        },
                        "text": {
                          "type": "string",
                          "description": "文本内容（Plain 类型）"
                        },
                        "url": {
                          "type": "string",
                          "description": "图片 URL（Image 类型）"
                        },
                        "target": {
                          "type": "string",
                          "description": "@ 的目标 ID（At 类型）"
                        }
                      }
                    },
                    "example": [
                      {
                        "type": "Plain",
                        "text": "Hello, World!"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "发送成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "sent": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "example": -1
          },
          "msg": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  }
}
```
