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

# Listar mensagens

> Mensagens de WhatsApp ou Instagram. total representa toda a consulta. quoted_message.page indica a página da mensagem citada. Permissão da chave: crm/chats.read. O acesso também respeita a empresa e as permissões do usuário criador da chave.



## OpenAPI

````yaml /openapi.json get /integrations/external/chats/{id}/messages
openapi: 3.0.3
info:
  title: >-
    Integração Externa - Leads, Oportunidades, Tarefas, Arquivos, Propostas,
    Chats, Satisfação e Campos Personalizados
  version: 1.0.0
  description: >
    Documentação oficial da API externa da Wegly para campos personalizados,
    leads, oportunidades, tarefas, arquivos, propostas, chats e satisfação
    (`/integrations/external/custom-fields`, `/integrations/external/files`,
    `/integrations/external/leads`, `/integrations/external/deals`,
    `/integrations/external/tasks`, `/integrations/external/proposals`,
    `/integrations/external/chats` e `/integrations/external/satisfaction`).
    Todas as descrições estão em português e refletem as regras aplicadas pelo
    serviço.
servers:
  - url: https://api.wegly.com.br
    description: Ambiente de produção Wegly
security:
  - bearerAuth: []
tags:
  - name: Campos Personalizados
    description: >-
      Consulta dos campos personalizados disponíveis para uso nas integrações
      externas.
  - name: Arquivos
    description: >-
      Upload e consulta de arquivos vinculados diretamente a leads ou
      oportunidades. Arquivos de proposta usam as rotas de anexos em Propostas.
  - name: Leads
    description: >-
      Operações de listagem, criação, consulta e atualização de leads via
      integração externa.
  - name: Oportunidades
    description: Operações de criação de oportunidades (deals) via integração externa.
  - name: Tarefas
    description: >-
      Operações de listagem, criação, consulta, atualização e remoção de tarefas
      vinculadas a leads, oportunidades, entregas, pessoas, organizações ou
      clientes.
  - name: Satisfação
    description: >-
      Geração de links públicos para formulários de satisfação via integração
      externa.
  - name: Propostas
    description: >-
      Operações de listagem, criação, consulta, atualização e remoção de
      propostas via integração externa, incluindo seus anexos (arquivos e
      documentos da biblioteca).
  - name: Chats
    description: >-
      Operações principais de listagem, criação, consulta e resumo de não lidas
      de chats via integração externa.
paths:
  /integrations/external/chats/{id}/messages:
    get:
      tags:
        - Chats
      summary: Listar mensagens
      description: >-
        Mensagens de WhatsApp ou Instagram. total representa toda a consulta.
        quoted_message.page indica a página da mensagem citada. Permissão da
        chave: crm/chats.read. O acesso também respeita a empresa e as
        permissões do usuário criador da chave.
      operationId: externalChatsMessages
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: UUID da conversa.
        - name: search
          in: query
          required: false
          schema:
            type: string
          description: Busca textual, quando suportada pela operação.
        - name: skip
          in: query
          required: false
          schema:
            type: number
            default: 0
          description: >-
            Quantidade de registros a pular; valores negativos são normalizados
            para zero.
        - name: take
          in: query
          required: false
          schema:
            type: number
            default: 20
          description: Quantidade por página. O serviço limita o resultado a 100 registros.
        - name: order
          in: query
          required: false
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
          description: Ordenação cronológica das mensagens/eventos.
      responses:
        '200':
          description: Operação realizada.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatMessageListResponse'
        '400':
          description: Payload ou regra de negócio inválidos.
        '401':
          description: >-
            Chave de integração ausente, inválida, inativa ou expirada, ou
            domínio de origem não autorizado para a chave.
        '403':
          description: Permissão da chave ou do usuário insuficiente para o recurso.
        '404':
          description: Conversa ou recurso associado não encontrado no escopo acessível.
        '429':
          description: Limite de requisições da integração excedido.
        '500':
          description: Falha interna ou na comunicação com o provedor.
components:
  schemas:
    ChatMessageListResponse:
      type: object
      properties:
        total:
          type: integer
          description: Total de registros que correspondem à consulta.
        records:
          type: array
          items:
            anyOf:
              - $ref: '#/components/schemas/ChatMessage'
              - $ref: '#/components/schemas/ChatInstagramMessage'
      required:
        - total
        - records
    ChatMessage:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          $ref: '#/components/schemas/ChatMessageTypeEnum'
        origin:
          $ref: '#/components/schemas/ChatMessageOriginEnum'
        from_me:
          type: boolean
        sent_via:
          $ref: '#/components/schemas/ChatMessageSentViaEnum'
        status:
          $ref: '#/components/schemas/ChatMessageDeliveryStatusEnum'
        body_text:
          type: string
          nullable: true
        content_payload:
          type: object
          nullable: true
          additionalProperties: true
        reactions:
          type: array
          items:
            $ref: '#/components/schemas/ChatReaction'
        meta_timestamp:
          type: string
          format: date-time
        is_history:
          type: boolean
        history_phase:
          type: integer
          nullable: true
        history_chunk_order:
          type: integer
          nullable: true
        history_progress:
          type: integer
          nullable: true
        is_media_placeholder:
          type: boolean
        agent:
          type: object
          nullable: true
          properties:
            id:
              type: string
              format: uuid
            user:
              type: object
              allOf:
                - $ref: '#/components/schemas/ExternalUserSummary'
              nullable: true
        user:
          type: object
          allOf:
            - $ref: '#/components/schemas/ExternalUserSummary'
          nullable: true
        transcription:
          type: string
          nullable: true
        is_forwarded:
          type: boolean
        error_code:
          type: integer
          nullable: true
        error_message:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
        media:
          type: object
          allOf:
            - $ref: '#/components/schemas/ChatMedia'
          nullable: true
        call:
          type: object
          allOf:
            - $ref: '#/components/schemas/ChatMessageCall'
          nullable: true
        quoted_message:
          $ref: '#/components/schemas/ChatQuotedMessage'
        whatsapp_ai_agent_id:
          type: string
          format: uuid
          nullable: true
          description: Agente de IA que enviou a mensagem; null para pessoas e automações.
      required:
        - id
        - type
        - origin
        - from_me
        - sent_via
        - status
        - body_text
        - transcription
        - meta_timestamp
        - created_at
        - media
        - call
    ChatInstagramMessage:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          type: string
          description: Tipo normalizado da mensagem do canal.
        origin:
          type: string
          enum:
            - INBOUND
            - API_OUTBOUND
            - APP_ECHO
            - SYSTEM
        from_me:
          type: boolean
        sent_via:
          $ref: '#/components/schemas/ChatMessageSentViaEnum'
        status:
          type: string
          enum:
            - PROCESSING
            - SENT
            - DELIVERED
            - READ
            - FAILED
            - DELETED
          description: Status da mensagem no Instagram, em maiúsculas.
        body_text:
          type: string
          nullable: true
        content_payload:
          type: object
          nullable: true
          additionalProperties: true
        reactions:
          type: array
          items:
            $ref: '#/components/schemas/ChatReaction'
        meta_timestamp:
          type: string
          format: date-time
        is_history:
          type: boolean
        history_phase:
          type: integer
          nullable: true
        history_chunk_order:
          type: integer
          nullable: true
        history_progress:
          type: integer
          nullable: true
        is_media_placeholder:
          type: boolean
        agent:
          type: object
          nullable: true
          properties:
            id:
              type: string
              format: uuid
            user:
              type: object
              allOf:
                - $ref: '#/components/schemas/ExternalUserSummary'
              nullable: true
        user:
          type: object
          allOf:
            - $ref: '#/components/schemas/ExternalUserSummary'
          nullable: true
        crm_marketing_lead_source:
          type: array
          nullable: true
          items:
            type: object
            additionalProperties: true
        is_forwarded:
          type: boolean
        wamid:
          type: string
          nullable: true
        provider_message_id:
          type: string
          nullable: true
        ref_wamid:
          type: string
          nullable: true
        ref_provider_message_id:
          type: string
          nullable: true
        error_code:
          type: string
          nullable: true
          description: Código textual do erro, por exemplo `DELIVERY_UNKNOWN`.
        error_message:
          type: string
          nullable: true
        shared_content:
          type: object
          properties: {}
          nullable: true
          additionalProperties: true
        media:
          type: array
          items:
            $ref: '#/components/schemas/ChatInstagramAttachment'
        attachments:
          type: array
          items:
            $ref: '#/components/schemas/ChatInstagramAttachment'
        provider_timestamp:
          type: string
          format: date-time
        channel_type:
          type: string
          enum:
            - INSTAGRAM
        quoted_message:
          allOf:
            - $ref: '#/components/schemas/ChatInstagramMessage'
            - type: object
              properties:
                page:
                  type: integer
      required:
        - id
        - type
        - origin
        - from_me
        - sent_via
        - status
        - body_text
        - meta_timestamp
        - media
        - attachments
        - channel_type
    ChatMessageTypeEnum:
      type: string
      enum:
        - text
        - reaction
        - image
        - video
        - audio
        - document
        - template
        - interactive
        - location
        - call
        - contacts
        - unsupported
        - sticker
        - button
      description: >-
        Tipos mais comuns. Mensagens recebidas guardam o tipo informado pelo
        provedor, de modo que outros valores podem aparecer.
    ChatMessageOriginEnum:
      type: string
      enum:
        - INBOUND
        - API_OUTBOUND
        - MOBILE_APP_ECHO
        - SYSTEM
    ChatMessageSentViaEnum:
      type: string
      enum:
        - CONTACT
        - API
        - MOBILE_DEVICE
        - SYSTEM
    ChatMessageDeliveryStatusEnum:
      type: string
      enum:
        - processing
        - sent
        - delivered
        - read
        - failed
        - received
        - deleted
        - delivery_unknown
      description: >-
        Status persistido da mensagem; delivery_unknown indica que o resultado
        do envio ainda não foi confirmado.
    ChatReaction:
      type: object
      properties:
        id:
          type: string
          format: uuid
        emoji:
          type: string
        actor:
          type: string
          enum:
            - CONTACT
            - BUSINESS
            - SYSTEM
          description: '`SYSTEM` pode aparecer em reações do Instagram.'
        reactor_wa_id:
          type: string
        reactor_user_id:
          type: string
          format: uuid
          nullable: true
        created_at:
          type: string
          format: date-time
    ExternalUserSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        avatar:
          type: string
          nullable: true
    ChatMedia:
      type: object
      properties:
        id:
          type: string
          format: uuid
        mime_type:
          type: string
        file_name:
          type: string
          nullable: true
        is_downloaded:
          type: boolean
        url:
          type: string
          nullable: true
      required:
        - id
        - mime_type
        - file_name
        - is_downloaded
        - url
    ChatMessageCall:
      type: object
      properties:
        id:
          type: string
          format: uuid
        status:
          type: string
          enum:
            - RINGING
            - IN_PROGRESS
            - COMPLETED
            - MISSED
            - REJECTED
            - FAILED
            - CANCELED
        direction:
          type: string
          enum:
            - INBOUND
            - OUTBOUND
        started_at:
          type: string
          format: date-time
          nullable: true
        ended_at:
          type: string
          format: date-time
          nullable: true
        duration_ms:
          type: integer
        recording_processed:
          type: boolean
        recording_available:
          type: boolean
        has_recording:
          type: boolean
    ChatQuotedMessage:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          $ref: '#/components/schemas/ChatMessageTypeEnum'
        origin:
          $ref: '#/components/schemas/ChatMessageOriginEnum'
        from_me:
          type: boolean
        sent_via:
          $ref: '#/components/schemas/ChatMessageSentViaEnum'
        status:
          $ref: '#/components/schemas/ChatMessageDeliveryStatusEnum'
        body_text:
          type: string
          nullable: true
        content_payload:
          type: object
          nullable: true
          additionalProperties: true
        reactions:
          type: array
          items:
            $ref: '#/components/schemas/ChatReaction'
        meta_timestamp:
          type: string
          format: date-time
        is_history:
          type: boolean
        history_phase:
          type: integer
          nullable: true
        history_chunk_order:
          type: integer
          nullable: true
        history_progress:
          type: integer
          nullable: true
        is_media_placeholder:
          type: boolean
        agent:
          type: object
          nullable: true
          properties:
            id:
              type: string
              format: uuid
            user:
              type: object
              allOf:
                - $ref: '#/components/schemas/ExternalUserSummary'
              nullable: true
        user:
          type: object
          allOf:
            - $ref: '#/components/schemas/ExternalUserSummary'
          nullable: true
        transcription:
          type: string
          nullable: true
        is_forwarded:
          type: boolean
        error_code:
          type: integer
          nullable: true
        error_message:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
        media:
          type: object
          allOf:
            - $ref: '#/components/schemas/ChatMedia'
          nullable: true
        page:
          type: integer
          description: Página da mensagem citada na mesma ordenação/paginação.
        whatsapp_ai_agent_id:
          type: string
          format: uuid
          nullable: true
          description: Agente de IA que enviou a mensagem; null para pessoas e automações.
      required:
        - id
        - type
        - origin
        - status
        - page
    ChatInstagramAttachment:
      type: object
      properties:
        id:
          type: string
          format: uuid
        media_id:
          type: string
          nullable: true
        provider_media_id:
          type: string
          nullable: true
        provider_type:
          type: string
          nullable: true
        content_kind:
          type: string
        mime_type:
          type: string
          nullable: true
        file_name:
          type: string
          nullable: true
        file_size:
          type: number
          nullable: true
        storage_path:
          type: string
          nullable: true
        public_url:
          type: string
          nullable: true
        source_url:
          type: string
          nullable: true
        url:
          type: string
          nullable: true
        is_downloaded:
          type: boolean
        download_status:
          type: string
        metadata:
          type: object
          properties: {}
          nullable: true
          additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >-
        Chave de integração com prefixo wegly_, enviada em Authorization: Bearer
        <chave>. Não é JWT. A chave deve estar ativa, não excluída e dentro da
        validade. Com allowed_domain, Origin (ou Referer na ausência de Origin)
        precisa informar o hostname permitido. A empresa e as permissões são
        obtidas pela chave.

````

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