# Messages

> Nesta página, vamos nos aprofundar nos diferentes endpoints de mensagens que você pode usar para gerenciar mensagens programaticamente.
>
> - **Canonical URL:** https://www.builderbot.app/pt/messages
> - **Documentation Index:** https://www.builderbot.app/llms.txt
> - **Full Corpus:** https://www.builderbot.app/llms-full.txt

As mensagens são o que as conversas são feitas no protocolo — eles são os blocos de construção básicos de suas conversas com seus contatos de Protocolo. Nesta página, vamos nos aprofundar nos diferentes endpoints de mensagens que você pode usar para gerenciar mensagens programaticamente. Veremos como consultar, enviar, atualizar e excluir mensagens. 

## The message model

O modelo de mensagem contém todas as informações sobre as mensagens e anexos que envia aos seus contactos e grupos, incluindo a forma como os seus contactos reagiram a eles.

### Properties

Identificador único da mensagem.

Identificador único para a conversa à qual a mensagem Pertence.

O objecto de contacto do contacto que enviou a mensagem.

O conteúdo da mensagem.

Uma matriz de objetos de reação associados à mensagem.

Uma matriz de objetos anexos associados à mensagem.

Timestamp de quando a mensagem foi lida.

Data e hora de quando a mensagem foi criada.

Data e hora de quando a mensagem foi atualizada pela última vez.

---

## List all messages 

  

Este ponto de extremidade permite que você recupere uma lista paginada de todas as suas mensagens (em uma conversa, se um ID de conversa for fornecido). Por predefinição, são apresentadas no máximo dez mensagens por página.

    ### Optional attributes

    
      
        Limit to messages from a given conversation.
      
      
        Limit the number of messages returned.
      
    

  
  

    

    ```bash (cURL)
    curl -G https://api.protocol.chat/v1/messages \
      -H "Authorization: Bearer {token}" \
      -d conversation_id=xgQQXg3hrtjh7AvZ \
      -d limit=10
    ```

    ```js
    import ApiClient from '@example/protocol-api'

    const client = new ApiClient(token)

    await client.messages.list()
    ```

    ```python
    from protocol_api import ApiClient

    client = ApiClient(token)

    client.messages.list()
    ```

    ```php
    $client = new \Protocol\ApiClient($token);

    $client->messages->list();
    ```

    

    ```json (Response)
    {
      "has_more": false,
      "data": [
        {
          "id": "SIuAFUNKdSYHZF2w",
          "conversation_id": "xgQQXg3hrtjh7AvZ",
          "contact": {
            "id": "WAz8eIbvDR60rouK",
            "username": "KevinMcCallister",
            "phone_number": "1-800-759-3000",
            "avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
            "last_active_at": 705103200,
            "created_at": 692233200
          },
          "message": "It’s a nice night for a neck injury.",
          "reactions": [],
          "attachments": [],
          "read_at": 705103200,
          "created_at": 692233200,
          "updated_at": 692233200
        },
        {
          "id": "hSIhXBhNe8X1d8Et",
          // ..
        }
      ]
    }
    ```

  

---

## Send a message 

  

Este ponto de extremidade permite-lhe enviar uma nova mensagem para uma das suas conversas.

    ### Required attributes

    
      
Identificador único para a conversa à qual a mensagem Pertence.
      
      
O conteúdo da mensagem.
      
    

    ### Optional attributes

    
      
Uma matriz de objetos anexos associados à mensagem.
      
    

  
  

    

    ```bash (cURL)
    curl https://api.protocol.chat/v1/messages \
      -H "Authorization: Bearer {token}" \
      -d conversation_id="xgQQXg3hrtjh7AvZ" \
      -d message="You’re what the French call ‘les incompetents.’"
    ```

    ```js
    import ApiClient from '@example/protocol-api'

    const client = new ApiClient(token)

    await client.messages.send({
      conversation_id: 'xgQQXg3hrtjh7AvZ',
      message: 'You’re what the French call ‘les incompetents.’',
    })
    ```

    ```python
    from protocol_api import ApiClient

    client = ApiClient(token)

    client.messages.send(
      conversation_id="xgQQXg3hrtjh7AvZ",
      message="You’re what the French call ‘les incompetents.’",
    )
    ```

    ```php
    $client = new \Protocol\ApiClient($token);

    $client->messages->send([
      'conversation_id' => 'xgQQXg3hrtjh7AvZ',
      'message' => 'You’re what the French call ‘les incompetents.’',
    ]);
    ```

    

    ```json (Response)
    {
      "id": "gWqY86BMFRiH5o11",
      "conversation_id": "xgQQXg3hrtjh7AvZ",
      "contact": {
        "id": "inEIRvzjC6YLMX3o",
        "username": "LinnieMcCallister",
        "phone_number": "1-800-759-3000",
        "avatar_url": "https://assets.protocol.chat/avatars/linnie.jpg",
        "last_active_at": 705103200,
        "created_at": 692233200
      },
      "message": "You’re what the French call ‘les incompetents.’",
      "reactions": [],
      "attachments": [],
      "read_at": null,
      "created_at": 692233200,
      "updated_at": null
    }
    ```

  

---

## Retrieve a message 

  

   Este ponto de extremidade permite que você recupere uma mensagem fornecendo o ID da mensagem. Referir-se a [the list](#the-message-model) no topo desta página para ver quais propriedades estão incluídas com objetos de mensagem.

  
  

    

    ```bash (cURL)
    curl https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
      -H "Authorization: Bearer {token}"
    ```

    ```js
    import ApiClient from '@example/protocol-api'

    const client = new ApiClient(token)

    await client.messages.get('SIuAFUNKdSYHZF2w')
    ```

    ```python
    from protocol_api import ApiClient

    client = ApiClient(token)

    client.messages.get("SIuAFUNKdSYHZF2w")
    ```

    ```php
    $client = new \Protocol\ApiClient($token);

    $client->messages->get('SIuAFUNKdSYHZF2w');
    ```

    

    ```json (Response)
    {
      "id": "SIuAFUNKdSYHZF2w",
      "conversation_id": "xgQQXg3hrtjh7AvZ",
      "contact": {
        "id": "WAz8eIbvDR60rouK",
        "username": "KevinMcCallister",
        "phone_number": "1-800-759-3000",
        "avatar_url": "https://assets.protocol.chat/avatars/kevin.jpg",
        "last_active_at": 705103200,
        "created_at": 692233200
      },
      "message": "I’m traveling with my dad. He’s at a meeting. I hate meetings.",
      "reactions": [],
      "attachments": [],
      "read_at": 705103200,
      "created_at": 692233200,
      "updated_at": 692233200
    }
    ```

  

---

## Update a message 

  

Este ponto de extremidade permite que você execute uma atualização em uma mensagem. Exemplos de atualizações são adicionar uma reação, editar a mensagem ou adicionar um anexo.

    ### Optional attributes

    
      
O conteúdo da mensagem.
      
      
Uma matriz de objetos de reação associados à mensagem.
      
      
Uma matriz de objetos anexos associados à mensagem.
      
    

  
  

    

    ```bash (cURL)
    curl -X PUT https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
      -H "Authorization: Bearer {token}" \
      -d reactions[red_angry_face][]="KateMcCallister"
    ```

    ```js
    import ApiClient from '@example/protocol-api'

    const client = new ApiClient(token)

    await client.messages.update('SIuAFUNKdSYHZF2w', {
        reactions: {
            red_angry_face: ['KateMcCallister']
        }
    })
    ```

    ```python
    from protocol_api import ApiClient

    client = ApiClient(token)

    client.messages.update("SIuAFUNKdSYHZF2w",
        reactions={"red_angry_face": ["KateMcCallister"]})
    ```

    ```php
    $client = new \Protocol\ApiClient($token);

    $client->messages->update('SIuAFUNKdSYHZF2w', [
      'reactions' => [
        'red_angry_face' => ['KateMcCallister'],
      ],
    ]);
    ```

    

    ```json (Response)
    {
      "id": "SIuAFUNKdSYHZF2w",
      "conversation_id": "xgQQXg3hrtjh7AvZ",
      "contact": {
        "id": "WAz8eIbvDR60rouK",
        "username": "KevinMcCallister",
        "phone_number": "1-800-759-3000",
        "avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
        "last_active_at": 705103200,
        "created_at": 692233200
      },
      "message": "I'm not apologizing. I'd rather kiss a toilet seat.",
      "reactions": [
        {
          "red_angry_face": [
            "KateMcCallister"
          ]
        }
      ],
      "attachments": [],
      "read_at": 705103200,
      "created_at": 692233200,
      "updated_at": 692233200
    }
    ```

  

---

## Delete a message 

  

Este ponto de extremidade permite que você exclua mensagens de suas conversas. Observação: isso excluirá permanentemente a mensagem.

  
  

    

    ```bash (cURL)
    curl -X DELETE https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
      -H "Authorization: Bearer {token}"
    ```

    ```js
    import ApiClient from '@example/protocol-api'

    const client = new ApiClient(token)

    await client.messages.delete('SIuAFUNKdSYHZF2w')
    ```

    ```python
    from protocol_api import ApiClient

    client = ApiClient(token)

    client.messages.delete("SIuAFUNKdSYHZF2w")
    ```

    ```php
    $client = new \Protocol\ApiClient($token);

    $client->messages->delete('SIuAFUNKdSYHZF2w');
    ```
