[go: up one dir, main page]

Skip to content

ReadChat#

Test Postman

The method is aimed for marking messages in a chat as read. Either all messages or a specified message in a chat can be marked as read.

For the method to work correctly, the Receive webhooks on incoming messages and files setting should be enabled using the SetSettings method or through the console

Messages received after applying the settings receive the read status.
Messages received before applying the settings will remain in the delivered status.

Request#

To mark messages in a chat as read, you have to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/readChat/{{apiTokenInstance}}

For apiUrl, idInstance and apiTokenInstance request parameters, refer to Before you start section.

Request parameters#

Parameter Type Mandatory Description
chatId string Yes Chat Id
idMessage string No ID of the incoming message to be marked as read. If not specified, then all unread messages in the chat will be marked as read.

Request body example#

Read mark of a single message in the chat:

{
    "chatId": "11001234567@c.us",
    "idMessage": "B275A7AA0D6EF89BB9245169BDF174E6"
}

Read mark of all messages in the chat:

{
    "chatId": "11001234567@c.us"
}

Response#

Response parameters#

Parameter Type Description
setRead boolean Messages read mark flag

Response body example#

{
    "setRead": true
}

ReadChatMessage errors#

For a list of errors common to all methods, refer to Common errors section

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error

Request examples#

import requests

url = "{{apiUrl}}/waInstance{{idInstance}}/readChat/{{apiTokenInstance}}"

payload = "{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"idMessage\": \"B275A7AA0D6EF89BB9245169BDF174E6\"\r\n}\r\n"
headers = {
  'Content-Type': 'application/json'
}

response = requests.post(url, json=payload)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/readChat/{{apiTokenInstance}}
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "79001234567@c.us",
    "idMessage": "B275A7AA0D6EF89BB9245169BDF174E6"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/readChat/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

var jsonBody = "{\"chatId\": \"11001234567@c.us\",\"idMessage\": \"BAE5F4886F6F2D05\"}";

var requestEntity = new HttpEntity<>(jsonBody, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/readChat/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\"chatId\": \"11001234567@c.us\",\"idMessage\": \"BAE5F4886F6F2D05\"}")
    .asString();

System.out.println(response);
Sub ReadChat()
    Dim url As String
    Dim RequestBody As String
    Dim http As Object
    Dim response As String

    ' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
    url = "{{apiUrl}}/waInstance{{idInstance}}/readChat/{{apiTokenInstance}}"

    ' chatId - chat in which messages will be read (@c.us for private chats, @g.us for group chats)
    RequestBody = "{""chatId"":""71234567890@c.us""}"

    Set http = CreateObject("MSXML2.XMLHTTP")

    With http
        .Open "POST", url, False
        .setRequestHeader "Content-Type", "application/json"
        .send RequestBody
    End With

    response = http.responseText

    Debug.Print response

    ' Outputting the answer to the desired cell
    Range("A1").Value = response

    Set http = Nothing
End Sub