Enviar mensaje de texto
Texto libre dentro de la ventana de 24 horas de servicio al cliente. Fuera de esa ventana, debes usar una plantilla aprobada.
POST
https://api.wis.chat/v22.0/{tid}/messages
Ventana de 24 horas: sólo puedes enviar texto libre si el cliente te escribió en las últimas 24 horas. Si pasó más tiempo, el envío fallará y deberás usar una plantilla.
Payload
{
"messaging_product": "whatsapp",
"to": "593999999999",
"type": "text",
"text": {
"preview_url": false,
"body": "Hola Oscar 👋, tu pedido *#4521* ya fue despachado."
}
}Estructura del objeto text
| Campo | Tipo | Requerido | Descripción |
|---|---|---|---|
body |
string | requerido | Contenido del mensaje. Máx 4096 caracteres. Soporta emojis y formato WhatsApp. |
preview_url |
boolean | opcional | Si es true y el body contiene una URL, WhatsApp generará una vista previa con título e imagen. |
Formato WhatsApp en el body
WhatsApp soporta un formato simple tipo Markdown dentro del texto:
| Sintaxis | Resultado | Ejemplo |
|---|---|---|
*texto* | Negrita | *importante* |
_texto_ | Cursiva | _énfasis_ |
~texto~ | Tachado | ~precio anterior~ |
```texto``` | Código monoespaciado | ```RUC: 1234``` |
\n | Salto de línea | Línea 1\nLínea 2 |
Ejemplo con preview de URL
{
"messaging_product": "whatsapp",
"to": "593999999999",
"type": "text",
"text": {
"preview_url": true,
"body": "Mira nuestro nuevo producto en https://nouxsoft.com/neocrm 👀"
}
}Implementaciones
curl -X POST "https://api.wis.chat/v22.0/TU_ID_LINEA/messages" \ -H "Authorization: Bearer TU_CODIGO_SEGURIDAD" \ -H "Content-Type: application/json" \ -d '{ "messaging_product": "whatsapp", "to": "593999999999", "type": "text", "text": { "preview_url": false, "body": "Hola Oscar 👋, tu pedido *#4521* fue despachado." } }'
function enviarTextoWischat($tid, $token, $to, $body, $preview = false) { $payload = [ 'messaging_product' => 'whatsapp', 'to' => $to, 'type' => 'text', 'text' => [ 'preview_url' => $preview, 'body' => $body, ], ]; $ch = curl_init("https://api.wis.chat/v22.0/{$tid}/messages"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_HTTPHEADER => [ "Authorization: Bearer {$token}", 'Content-Type: application/json', ], ]); $res = json_decode(curl_exec($ch), true); curl_close($ch); return $res; } $res = enviarTextoWischat( 15, 'TU_CODIGO_SEGURIDAD', '593999999999', 'Hola Oscar 👋, tu pedido *#4521* fue despachado.' );
async function enviarTexto({ tid, token, to, body, previewUrl = false }) { const res = await fetch(`https://api.wis.chat/v22.0/${tid}/messages`, { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ messaging_product: 'whatsapp', to, type: 'text', text: { preview_url: previewUrl, body }, }), }); return await res.json(); }
import requests def enviar_texto(tid, token, to, body, preview_url=False): res = requests.post( f'https://api.wis.chat/v22.0/{tid}/messages', headers={ 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json', }, json={ 'messaging_product': 'whatsapp', 'to': to, 'type': 'text', 'text': {'preview_url': preview_url, 'body': body}, } ) return res.json()