waiaconnect

Documentazione / Essenziale

Segnare un messaggio come letto (e mostrare «sta scrivendo…»)

POST /v1/messages/read

Markdown

POST /v1/messages/read con {"messageId": "wamid…"}: l'id di un messaggio che hai RICEVUTO (data.message.id di message.received). Va nel corpo, non nell'URL (un URL finisce nei log di accesso, e l'id contiene il numero del contatto). Il contatto vede le spunte blu; Meta segna come letti anche i messaggi precedenti di quella chat. Aggiungi "typing": true per mostrare anche «sta scrivendo…»: sparisce quando rispondi o dopo 25 secondi, a seconda di cosa succede prima.

Non è un invio: non crea un msg_…, non consuma quota, non conta come messaggio e non richiede Idempotency-Key (segnarlo due volte non fa danni). Funziona allo stesso modo sui numeri Cloud API e Coexistence.

# messageId comes from a message.received event: data.message.id
curl -X POST https://api.waiaconnect.com/v1/messages/read \
  -H "Authorization: Bearer wc_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messageId": "wamid.HBgN…AA==", "typing": true}'
# → { "messageId": "wamid.…", "status": "read", "typing": true, "typingSeconds": 25, "connectionId": "conn_…" }
const res = await fetch("https://api.waiaconnect.com/v1/messages/read", {
  method: "POST",
  headers: { "Authorization": "Bearer wc_live_YOUR_API_KEY", "Content-Type": "application/json" },
  body: JSON.stringify({
    messageId: event.data.message.id, // from message.received
    typing: true                      // omit to only mark as read
  })
});
console.log(res.status); // 200 = read (and "typing…" shown up to 25 s)
<?php
$ch = curl_init("https://api.waiaconnect.com/v1/messages/read");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ["Authorization: Bearer wc_live_YOUR_API_KEY", "Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode([
    "messageId" => $event["data"]["message"]["id"], // from message.received
    "typing" => true,                               // omit to only mark as read
  ]),
]);
$res = json_decode(curl_exec($ch), true);
echo $res["status"]; // read
import requests
res = requests.post("https://api.waiaconnect.com/v1/messages/read",
  headers={"Authorization": "Bearer wc_live_YOUR_API_KEY"},
  json={"messageId": event["data"]["message"]["id"],  # from message.received
        "typing": True})                              # omit to only mark as read
print(res.json()["status"])  # read

Meta accetta solo messaggi ricevuti negli ultimi 30 giorni → MESSAGE_TOO_OLD. Un id msg_… → INVALID_MESSAGE_ID; un id di UN ALTRO account → INBOUND_MESSAGE_NOT_FOUND (non confermiamo mai che esista).

Mostra «sta scrivendo…» solo se stai per rispondere (lo chiede Meta): un contatto che lo vede e poi non riceve nulla resta peggio di uno che non ha visto niente.