waiaconnect

Documentazione / Completo

Inviare un modello

POST /v1/messages

Markdown

I modelli si inviano per nome: POST /v1/messages con type: "template" e template: { name, language, components }. Il modello deve essere approvato in Meta; components contiene le sue variabili. Se è tuo e non è approvato, ti restituiamo 422 TEMPLATE_NOT_APPROVED prima di chiamare Meta; se non l'abbiamo ancora sincronizzato, lo lasciamo passare.

curl -X POST https://api.waiaconnect.com/v1/messages \
  -H "Authorization: Bearer wc_live_YOUR_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":"conn_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","to":"5493511234567","type":"template","template":{"name":"hello_world","language":"es","components":[]}}'
# The template must already be APPROVED in Meta. `components` carries its variables.
const res = await fetch("https://api.waiaconnect.com/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": "Bearer wc_live_YOUR_API_KEY",
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json"
  },
  // The template must already be APPROVED in Meta; `components` carries its variables.
  body: JSON.stringify({
  "connectionId": "conn_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "5493511234567",
  "type": "template",
  "template": {
    "name": "hello_world",
    "language": "es",
    "components": []
  }
})
});
console.log(await res.json());
<?php
$ch = curl_init("https://api.waiaconnect.com/v1/messages");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer wc_live_YOUR_API_KEY",
    "Idempotency-Key: " . bin2hex(random_bytes(16)),
    "Content-Type: application/json",
  ],
  // The template must already be APPROVED in Meta.
  CURLOPT_POSTFIELDS => json_encode(["connectionId" => "conn_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","to" => "5493511234567","type" => "template","template" => ["name" => "hello_world","language" => "es","components" => []]]),
]);
echo curl_exec($ch);
import requests, uuid
res = requests.post("https://api.waiaconnect.com/v1/messages",
  headers={
    "Authorization": "Bearer wc_live_YOUR_API_KEY",
    "Idempotency-Key": str(uuid.uuid4()),
  },
  # The template must already be APPROVED in Meta; "components" carries its variables.
  json={"connectionId":"conn_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","to":"5493511234567","type":"template","template":{"name":"hello_world","language":"es","components":[]}})
print(res.json())

Da dove viene il name: da GET /v1/templates (campi name + language di ogni riga), oppure dalla sezione Modelli del pannello. È il nome in Meta, non il titolo che gli hai dato a schermo, e funziona solo se quella riga è in APPROVED.

Fuori dalla finestra di servizio di 24h, Meta esige un modello approvato. Se mandi comunque testo libero, il POST risponde 202 e il rifiuto arriva dopo, nello stato del messaggio: failed con lastErrorCode: WINDOW_24H_EXPIRED (il 131047 di Meta). Non è un errore HTTP.

La finestra di 24 ore: puoi scrivere liberamente solo entro le 24h dall'ultimo messaggio del cliente. Dopo ti serve un modello approvato. È il motivo per cui esistono.