waiaconnect

Documentación / Completo

Enviar una plantilla

POST /v1/messages

Las plantillas se envían por nombre: POST /v1/messages con type: "template" y template: { name, language, components }. La plantilla tiene que estar aprobada en Meta; components lleva sus variables. Si es tuya y no está aprobada, te devolvemos 422 TEMPLATENOTAPPROVED antes de llamar a Meta; si todavía no la sincronizamos, la dejamos pasar.

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())

Fuera de la ventana de 24h de servicio, Meta exige una plantilla aprobada (error 131047 si mandás texto libre).

La ventana de 24 horas: sólo podés escribir libremente dentro de las 24h del último mensaje del cliente. Después necesitás una plantilla aprobada. Ese es el motivo por el que existen.