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

# 从指定的聊天室获取消息

> 从指定的聊天对话中获取包含过滤选项的消息



## OpenAPI

````yaml /zh/openapi.yml get /chat/{chat_jid}/messages
openapi: 3.0.0
info:
  title: WhatsApp API 多设备
  version: 9.7.0
  description: |
    此 API 用于通过 API 发送什么应用。

    Web 仪表板是一个单独的项目(gowa-ui)； 服务器下载它的
    最新版本资产并在 `/` 处服务(或在
    APP_UI_ENABLED=false时返回一个 JSON 横幅)。

    设备范围：
    - 在所有设备范围的REST 调用上发送 `X-Device-Id` 。
    - WebSocket: 连接到"/w?device_id=<id>`.
    - WebSocket 身份验证（启用基本身份验证时）：浏览器无法为
      WebSocket 连接设置 Authorization 请求头，因此还需在
      查询字符串中传入 `&authorization=<base64(user:pass)>`。 在
      生产中使用TLS ，因为凭据在 URL 中可见。
servers:
  - url: http://localhost:3000
security:
  - basicAuth: []
tags:
  - name: app
    description: 初始连接到 Whatsapp 服务器
  - name: device
    description: 多设备支持的设备管理
  - name: user
    description: 获取信息
  - name: send
    description: 发送消息 (Text/Image/File/Video)。
  - name: message
    description: 消息操作 (撤销/react/update)。
  - name: call
    description: 通话管理 (拒绝来电)
  - name: chat
    description: 聊天对话和消息
  - name: group
    description: 组设置
  - name: newsletter
    description: 通讯设置
  - name: chatwoot
    description: 客户支持的聊天窗口集成
paths:
  /chat/{chat_jid}/messages:
    get:
      tags:
        - chat
      summary: 从指定的聊天室获取消息
      description: 从指定的聊天对话中获取包含过滤选项的消息
      operationId: getChatMessages
      parameters:
        - $ref: '#/components/parameters/DeviceIdHeader'
        - in: path
          name: chat_jid
          schema:
            type: string
          required: true
          description: >-
            聊天 JID (e.g. phone@s.whatsapp.net for individ或groupid@g.us for
            group). 接受百分比编码值(如组%40g.us)。
          example: 6289685028129@s.whatsapp.net
        - name: limit
          in: query
          schema:
            type: integer
            default: 50
            maximum: 100
          description: 返回消息的最大数量
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
          description: 要跳过的消息数量 (用于分页)
        - name: start_time
          in: query
          schema:
            type: string
            format: date-time
          description: 过滤来自此时间戳的消息 (ISO 8601 格式)
        - name: end_time
          in: query
          schema:
            type: string
            format: date-time
          description: 在此时间戳之前过滤消息 (ISO 8601 格式)
        - name: media_only
          in: query
          schema:
            type: boolean
            default: false
          description: 仅返回带有媒体内容的消息
        - name: is_from_me
          in: query
          schema:
            type: boolean
          description: >-
            按发件人过滤消息(您发送的消息为 true，对于收到的消息为 false)。 当提供了唯一的媒体=true 和
            isFromMe=false 时，介质仅优先，并且将返回所有媒体信息，而不论发送者为何。
        - name: search
          in: query
          schema:
            type: string
          description: 按内容文本搜索消息
      responses:
        '200':
          description: 好的
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatMessagesResponse'
        '400':
          description: 错误请求
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBadRequest'
        '401':
          description: 未授权
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorUnauthorized'
        '404':
          description: 找不到聊天
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorNotFound'
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInternalServer'
components:
  parameters:
    DeviceIdHeader:
      name: X-Device-Id
      in: header
      required: false
      description: |
        多设备支持的设备标识符。 当多个设备被注册时需要.
        如果只有一个设备被注册，它将被用作默认。
        也可以以 `device_id` 查询参数提供。
      schema:
        type: string
        example: my-device-id
  schemas:
    ChatMessagesResponse:
      type: object
      properties:
        code:
          type: string
          example: SUCCESS
        message:
          type: string
          example: Success get chat messages
        results:
          type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/ChatMessage'
            pagination:
              type: object
              properties:
                limit:
                  type: integer
                  example: 50
                offset:
                  type: integer
                  example: 0
                total:
                  type: integer
                  example: 1250
            chat_info:
              $ref: '#/components/schemas/Chat'
    ErrorBadRequest:
      type: object
      properties:
        code:
          type: string
          example: 400
          description: HTTP 状态代码
        message:
          type: string
          example: field cannot be blank
          description: 详细错误消息
        results:
          type: object
          example: null
          description: 附加数据
    ErrorUnauthorized:
      type: object
      properties:
        code:
          type: string
          example: 401
          description: HTTP 状态代码
        message:
          type: string
          example: Unauthorized access
          description: 详细错误消息
        results:
          type: object
          example: null
          description: 附加数据
    ErrorNotFound:
      type: object
      properties:
        code:
          type: string
          example: 404
          description: HTTP 状态代码
        message:
          type: string
          example: Chat not found
          description: 详细错误消息
        results:
          type: object
          example: null
          description: 附加数据
    ErrorInternalServer:
      type: object
      properties:
        code:
          type: string
          example: INTERNAL_SERVER_ERROR
          description: SYSTEM_CODE_ERROR
        message:
          type: string
          example: you are not loggin
          description: 详细错误消息
        results:
          type: object
          example: null
          description: 附加数据
    ChatMessage:
      type: object
      properties:
        id:
          type: string
          example: 3EB0B430B6F8F1D0E053AC120E0A9E5C
          description: 消息ID
        chat_jid:
          type: string
          example: 6289685028129@s.whatsapp.net
          description: 聊天该消息属于的 JID
        sender_jid:
          type: string
          example: 6289685028129@s.whatsapp.net
          description: Sender JID
        sender_display_name:
          type: string
          example: Saved Contact
          description: >-
            可读的发件人标签在生成此响应时被动态解析，而不是与消息一起存储。
            对于其他发送者，它更喜欢保存的联系人全名、然后是存储的联系人推送名称、企业名称、JID用户部分和原始JID。
            对于活动帐户，它更喜欢设备显示名称(请回到存储帐户推送名称) 帐户 JID 用户部分，帐户 JID，发送者JID
            用户部分，以及原始发送者JID。 因此，联系人重命名可以更改历史消息返回的标签。 `sender_jid`仍然是稳定的发件人标识符。
        content:
          type: string
          example: Hello, how are you?
          description: 消息文本内容
        timestamp:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00Z'
          description: 消息时间戳
        is_from_me:
          type: boolean
          example: false
          description: 此消息是否由当前用户发送
        media_type:
          type: string
          example: image
          nullable: true
          description: 媒体类型(图像、视频、音频、文档等)。 值 `call` 表示一个存储的来电日志。
        reactions:
          type: array
          description: 附加到此消息的表情反应
          items:
            $ref: '#/components/schemas/ChatReaction'
        call_metadata:
          type: string
          example: '{"call_id":"ABC","auto_rejected":false}'
          description: 当media_type 是 `call` 时，JSON 字符串与调用详细信息。 不适用时(匹配Go json omitempty)。
        referral_metadata:
          type: string
          example: '{"ctwa_clid":"clid_123","source_app":"whatsapp"}'
          description: >-
            当消息来自点击到WhatsApp 时，使用 Meta 广告推荐/属性的JSON 字符串。 不适用时(匹配Go json
            omitempty)。
        context_metadata:
          type: string
          example: '{"replied_to_id":"AC625C65EA7143E71D784176C4A90A93"}'
          description: >-
            JSON 字符串中包含回复的消息 ID 当回复上下文被知时。 从直播、发送和历史同步消息中捕获。 在没有回复上下文时, 包括旧的存储行,
            直到它们在上下文中被摄取.
        filename:
          type: string
          example: photo.jpg
          nullable: true
          description: 媒体消息原始文件名
        url:
          type: string
          example: https://media.example.com/file.jpg
          nullable: true
          description: 媒体文件 URL
        file_length:
          type: integer
          example: 1024768
          nullable: true
          description: 媒体消息的文件大小（字节）
        created_at:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00Z'
          description: 记录创建时间戳
        updated_at:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00Z'
          description: 记录上次更新的时间戳
    Chat:
      type: object
      properties:
        jid:
          type: string
          example: 6289685028129@s.whatsapp.net
          description: 聊天JID 标识符
        name:
          type: string
          example: John Doe
          description: 聊天显示名称
        last_message_time:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00Z'
          description: 最后消息的时间戳
        ephemeral_expiration:
          type: integer
          example: 0
          description: 短信过期时间（以秒计） (0=禁用)
        created_at:
          type: string
          format: date-time
          example: '2024-01-10T08:00:00Z'
          description: 聊天创建时间戳
        updated_at:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00Z'
          description: 聊天最后更新时间戳
        archived:
          type: boolean
          example: false
          description: 聊天是否已存档
    ChatReaction:
      type: object
      properties:
        emoji:
          type: string
          example: 👍
          description: 反应中使用的表情符号
        sender_jid:
          type: string
          example: 628123456789@s.whatsapp.net
          description: 响应用户的JID
        sender_display_name:
          type: string
          example: Saved Contact
          description: >-
            可读的发件人标签在生成此响应时动态解析，而不是与反应一起存储。
            对于其他发送者，它更喜欢保存的联系人全名、然后是存储的联系人推送名称、企业名称、JID用户部分和原始JID。
            对于活动帐户，它更喜欢设备显示名称(请回到存储帐户推送名称) 帐户 JID 用户部分，帐户 JID，发送者JID
            用户部分，以及原始发送者JID。 因此，联系人重命名可以更改为历史反应返回的标签。 `sender_jid`仍然是稳定的发件人标识符。
        is_from_me:
          type: boolean
          example: false
          description: 此反应是否由当前用户作出。
        timestamp:
          type: string
          format: date-time
          example: '2024-01-15T10:31:00Z'
          description: 收到反应时
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````

## Related topics

- [获取聊天列表](https://gowa-docs.mintlify.site/zh/api-reference/chat/获取聊天列表.md)
- [获取设备的聊天窗口配置](https://gowa-docs.mintlify.site/zh/api-reference/chatwoot/获取设备的聊天窗口配置.md)
- [正在接收消息](https://gowa-docs.mintlify.site/zh/examples/receiving-messages.md)
- [固定或取消置顶聊天](https://gowa-docs.mintlify.site/zh/api-reference/chat/固定或取消置顶聊天.md)
- [归档或取消归档聊天](https://gowa-docs.mintlify.site/zh/api-reference/chat/归档或取消归档聊天.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.