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

# Buscar Mensagens

> Retorna mensagens de uma conversa específica

## Query Parameters

<ParamField query="channel_id" type="string" required>
  UUID do canal
</ParamField>

<ParamField query="remote_jid" type="string" required>
  JID do WhatsApp (ex: `5511999999999@s.whatsapp.net`)
</ParamField>

<ParamField query="limit" type="integer" default="50">
  Limite de mensagens a retornar
</ParamField>

<ParamField query="offset" type="integer" default="0">
  Deslocamento para paginação
</ParamField>

## Response

<ResponseField name="array" type="Message[]">
  Lista de mensagens ordenadas por timestamp
</ResponseField>

<Expandable title="Propriedades da Mensagem">
  <ResponseField name="id" type="string">
    UUID da mensagem
  </ResponseField>

  <ResponseField name="content" type="string">
    Conteúdo da mensagem
  </ResponseField>

  <ResponseField name="role" type="string">
    Quem enviou: `user`, `assistant`, `agent`
  </ResponseField>

  <ResponseField name="message_type" type="string">
    Tipo: `text`, `image`, `audio`, `video`, `document`
  </ResponseField>

  <ResponseField name="url" type="string">
    URL da mídia (se aplicável)
  </ResponseField>

  <ResponseField name="timestamp" type="string">
    Data/hora da mensagem
  </ResponseField>

  <ResponseField name="status" type="string">
    Status: `sent`, `delivered`, `read`
  </ResponseField>
</Expandable>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.leavo.ai/backend/messages?channel_id=uuid&remote_jid=5511999999999@s.whatsapp.net&limit=20" \
    -H "Authorization: Bearer sua_chave_aqui"
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    channel_id: 'uuid-do-canal',
    remote_jid: '5511999999999@s.whatsapp.net',
    limit: '20'
  });

  const response = await fetch(
    `https://api.leavo.ai/backend/messages?${params}`,
    {
      headers: {
        'Authorization': 'Bearer sua_chave_aqui'
      }
    }
  );

  const messages = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.leavo.ai/backend/messages',
      params={
          'channel_id': 'uuid-do-canal',
          'remote_jid': '5511999999999@s.whatsapp.net',
          'limit': 20
      },
      headers={'Authorization': 'Bearer sua_chave_aqui'}
  )

  messages = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  [
    {
      "id": "msg-uuid-1",
      "content": "Olá, gostaria de mais informações",
      "role": "user",
      "message_type": "text",
      "timestamp": "2024-01-15T10:30:00Z",
      "status": "read"
    },
    {
      "id": "msg-uuid-2",
      "content": "Olá! Claro, posso ajudar. Qual produto você tem interesse?",
      "role": "assistant",
      "message_type": "text",
      "timestamp": "2024-01-15T10:30:05Z",
      "status": "delivered"
    },
    {
      "id": "msg-uuid-3",
      "content": "",
      "role": "user",
      "message_type": "image",
      "url": "https://storage.leavo.ai/images/abc123.jpg",
      "timestamp": "2024-01-15T10:31:00Z",
      "status": "read"
    }
  ]
  ```
</ResponseExample>
