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

# Botメッセージの送信

> Botからメッセージを送信します



## OpenAPI

````yaml post /bots/{bot_user_id}/channels/{channel_id}/messages
openapi: 3.0.0
info:
  title: Rheel Chat API
  version: 1.0.1
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
  description: >-
    RheelのChat API仕様です。主に以下の2種類のエンドポイントを提供し、 認証方式によって利用方法が異なります。

    1. **Server Request**

    管理者（あるいはバックエンドサーバー）が、管理画面で発行したアプリケーション独自のAPI Key を用いた、ユーザー管理 (ユーザー作成・削除など)
    やセッショントークンの発行などを行う際のエンドポイントです。


    2. **User Request**

    セッショントークン発行のエンドポイントを介して取得したセッショントークンを用いた、メッセージの投稿やチャンネルの閲覧・参加などのエンドポイントです。


    ![ユーザーリクエストとサーバーリクエストの概念図](./images/request-image.png)


    ---

    ## 認証の流れ

    1. 管理画面からアプリケーション独自の API Key を取得します。

    これはサーバーサイド(管理系)の認証に使用します。


    2. エンドユーザーがログインすると、上記の API Key を用いてユーザーごとに

    セッショントークンを発行します。


    3. ユーザーは、フロントエンド (Web クライアントやモバイルアプリなど) から

    セッショントークンを利用してチャットサービスにアクセスし、メッセージの送受信や

    チャンネルの閲覧・参加を行います。



    Webhookのイベントやユーザーの作成・削除、権限管理などについて、詳しくはヘルプページをご覧ください。
servers:
  - url: https://<application_id>.chat.rheel.net/v1
    description: 本番サーバー
    variables:
      application_id:
        default: YOUR_APP_ID（RheelチャットインスタンスのアプリケーションID）
security: []
tags:
  - name: Users
  - name: Channels
  - name: Messages
  - name: Bots
paths:
  /bots/{bot_user_id}/channels/{channel_id}/messages:
    post:
      tags:
        - Bots
      summary: Botメッセージの送信
      description: Botからメッセージを送信します
      operationId: Bots_sendMessage
      parameters:
        - name: bot_user_id
          in: path
          required: true
          description: Botの一意なID
          schema:
            $ref: '#/components/schemas/UserId'
        - name: channel_id
          in: path
          required: true
          description: メッセージを投稿するチャンネルID
          schema:
            $ref: '#/components/schemas/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Bots.CreateBotMessageRequest'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Bots.BotMessage'
        '400':
          description: 入力内容が不正です
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.BadRequestError'
        '401':
          description: 認証に失敗しました
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.UnauthorizedError'
        '403':
          description: アクセス権がありません
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.ForbiddenError'
        '404':
          description: リソースが存在しません
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.NotFoundError'
        '500':
          description: サーバーでエラーが発生しました。時間をおいて再度お試しください。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.InternalServerError'
      security:
        - ServerApiKeyAuth: []
components:
  schemas:
    UserId:
      type: string
      minLength: 1
      maxLength: 100
      pattern: ^[a-zA-Z0-9_-]+$
    ChannelId:
      type: string
      minLength: 1
      maxLength: 100
      pattern: ^[a-zA-Z0-9_-]+$
    Bots.CreateBotMessageRequest:
      type: object
      required:
        - content
      properties:
        content:
          type: string
          maxLength: 32000
          description: メッセージ本文
        thread_id:
          type: string
          nullable: true
          format: uuid
          description: スレッドメッセージとして返信する場合の親メッセージID
        metadata:
          type: object
          additionalProperties: {}
          nullable: true
          description: 任意の追加メタデータ
        mentions:
          type: array
          items:
            $ref: '#/components/schemas/Messages.MentionInput'
          description: メンション一覧（送信時）
    Bots.BotMessage:
      type: object
      required:
        - content
      properties:
        id:
          type: string
          format: uuid
          description: メッセージID
          readOnly: true
        content:
          type: string
          maxLength: 32000
          description: メッセージ本文
        channel_id:
          allOf:
            - $ref: '#/components/schemas/ChannelId'
          description: メッセージが属するチャンネルのID
          readOnly: true
        thread_id:
          type: string
          nullable: true
          format: uuid
          description: スレッドメッセージとして返信する場合の親メッセージID
        sent_by:
          allOf:
            - $ref: '#/components/schemas/Users.UserBasic'
          description: メッセージを送信したユーザー
          readOnly: true
        read_by:
          type: array
          items:
            $ref: '#/components/schemas/Users.UserBasic'
          description: 既読したユーザーの一覧
          readOnly: true
        reactions:
          type: array
          items:
            $ref: '#/components/schemas/Messages.Reaction'
          description: メッセージに付与されたリアクション一覧
          readOnly: true
        mentions:
          type: array
          items:
            $ref: '#/components/schemas/Messages.Mention'
          description: メンション情報一覧
          readOnly: true
        edited_at:
          type: string
          format: date-time
          nullable: true
          description: 編集日時
          readOnly: true
        created_at:
          type: string
          format: date-time
          description: 作成日時
          readOnly: true
        updated_at:
          type: string
          format: date-time
          nullable: true
          description: 更新日時
          readOnly: true
        deleted_at:
          type: string
          format: date-time
          nullable: true
          description: 削除日時
          readOnly: true
        metadata:
          type: object
          additionalProperties: {}
          nullable: true
          description: 任意の追加メタデータ
    Error.BadRequestError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - BAD_REQUEST
            errors:
              type: array
              items:
                $ref: '#/components/schemas/Error.ValidationError'
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.BadRequestResponse'
      description: 入力内容が不正です
    Error.UnauthorizedError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - UNAUTHORIZED
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.UnauthorizedResponse'
      description: 認証に失敗しました
    Error.ForbiddenError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - FORBIDDEN
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.ForbiddenResponse'
      description: アクセス権がありません
    Error.NotFoundError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - NOT_FOUND
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.NotFoundResponse'
      description: リソースが存在しません
    Error.InternalServerError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - INTERNAL_SERVER_ERROR
          required:
            - message
            - code
      allOf:
        - type: object
          description: ''
      description: サーバーでエラーが発生しました。時間をおいて再度お試しください。
    Messages.MentionInput:
      type: object
      required:
        - type
      properties:
        type:
          allOf:
            - $ref: '#/components/schemas/Messages.MentionType'
          description: メンションタイプ
        user_id:
          type: string
          description: メンション対象のユーザーID（userタイプの場合のみ必須）
      description: メンション情報（送信時）
    Users.UserBasic:
      type: object
      required:
        - id
        - display_name
        - role
      properties:
        id:
          allOf:
            - $ref: '#/components/schemas/UserId'
          description: ユーザーの一意な識別子
        display_name:
          type: string
          minLength: 1
          maxLength: 200
          description: ユーザーの表示名
        icon_url:
          type: string
          nullable: true
          description: ユーザーアイコンのURL
        role:
          allOf:
            - $ref: '#/components/schemas/Users.UserRole'
          description: ユーザーの権限・役割(Admin:管理者, Member:一般ユーザー)
        metadata:
          type: object
          additionalProperties: {}
          nullable: true
          description: 任意の追加メタデータ
      description: 簡易ユーザー情報（IDと基本情報のみ）
    Messages.Reaction:
      type: object
      required:
        - id
        - message_id
        - emoji_code
        - user
        - created_at
      properties:
        id:
          type: string
          format: uuid
          description: リアクションID
          readOnly: true
        message_id:
          type: string
          format: uuid
          description: リアクションを付与するメッセージID
          readOnly: true
        emoji_code:
          type: string
          description: リアクションに用いる絵文字のコード
        user:
          allOf:
            - $ref: '#/components/schemas/Users.UserBasic'
          description: リアクションを付与したユーザー
          readOnly: true
        created_at:
          type: string
          format: date-time
          nullable: true
          description: リアクションが付与された日時
          readOnly: true
    Messages.Mention:
      type: object
      required:
        - type
      properties:
        type:
          allOf:
            - $ref: '#/components/schemas/Messages.MentionType'
          description: メンションタイプ
        user:
          allOf:
            - $ref: '#/components/schemas/Users.UserBasic'
          description: メンション対象のユーザー情報（userタイプの場合のみ）
      description: メンション情報（取得時）
    Error.ValidationError:
      type: object
      required:
        - field
        - message
        - code
      properties:
        field:
          type: string
        message:
          type: string
        code:
          type: string
      description: バリデーションエラー詳細
    TypeSpec.Http.BadRequestResponse:
      type: object
      description: The server could not understand the request due to invalid syntax.
    TypeSpec.Http.UnauthorizedResponse:
      type: object
      description: Access is unauthorized.
    TypeSpec.Http.ForbiddenResponse:
      type: object
      description: Access is forbidden.
    TypeSpec.Http.NotFoundResponse:
      type: object
      description: The server cannot find the requested resource.
    Messages.MentionType:
      type: string
      enum:
        - User
        - Channel
      description: メンションタイプ
    Users.UserRole:
      type: string
      enum:
        - Admin
        - Member
  securitySchemes:
    ServerApiKeyAuth:
      type: apiKey
      in: header
      name: X-Rheel-API-Key
      description: 管理系API呼び出し用のAPIキーを指定します

````