# Mensajes

En esta sección se encuentran los servicios que permiten enviar mensajes desde tu sistema directamente a un número de WhatsApp. Todos los tipos de mensaje se envían mediante una única solicitud `POST` al mismo endpoint, variando el campo `type` en el cuerpo de la solicitud.

#### Tipos de mensaje

{% hint style="info" %}
*Si el destinatario no te ha enviado un mensaje en las últimas 24 horas, solo podrás contactarlo mediante un mensaje de **plantilla (template)**. Para conversaciones activas, puedes usar cualquier tipo de mensaje*
{% endhint %}

{% stepper %}
{% step %}

### Mensaje de texto

Envía un mensaje de texto plano a tu destinatario. Ideal para respuestas rápidas, notificaciones simples o cualquier comunicación que no requiera archivos adjuntos.
{% endstep %}

{% step %}

### Mensaje de imagen

Envía una imagen desde una URL pública, con la opción de agregar un caption descriptivo.
{% endstep %}

{% step %}

### Mensaje de audio

Envía un archivo de audio en formatos como `.ogg`, `.mp3` o `.mp4`.
{% endstep %}

{% step %}

### Mensaje de documento

Comparte archivos como PDFs, hojas de cálculo o presentaciones, con nombre de archivo personalizado visible para el destinatario.
{% endstep %}

{% step %}

### Mensaje de ubicación

Comparte una ubicación geográfica con nombre y dirección, útil para indicar puntos de encuentro, sedes o cualquier lugar relevante.
{% endstep %}

{% step %}

### Mensaje de contacto

Comparte una tarjeta de contacto con nombre, teléfono y correo electrónico.
{% endstep %}

{% step %}

### Mensaje con plantilla (template)

Las plantillas permiten iniciar conversaciones con usuarios fuera de la ventana de 24 horas. La plantilla debe estar previamente aprobada por Meta. Para más detalle sobre cómo crear y gestionar plantillas, consulta la sección 📋 Plantillas.

{% hint style="warning" %}
*Enviar un mensaje sin plantilla a un número que no tiene una cuenta de WhatsApp activa, o que no te ha escrito en las últimas 24 horas, generará un error con código **470** en el webhook*
{% endhint %}
{% endstep %}
{% endstepper %}

#### Enviar mensajes

Todos los tipos de mensaje se envían al mismo endpoint. El campo `type` en el cuerpo de la solicitud determina qué tipo de contenido se enviará, y según ese valor debes incluir el objeto correspondiente.

## POST /messages

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Messages","description":"Send WhatsApp messages of various types (text, image, audio, video, document, location, contact, template)"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"schemas":{"SendMessageRequest":{"type":"object","required":["messaging_product","to","type"],"properties":{"messaging_product":{"type":"string","enum":["whatsapp"]},"recipient_type":{"type":"string","enum":["individual"]},"to":{"type":"string","description":"Recipient phone number in E.164 format"},"preview_url":{"type":"boolean","description":"Whether to show URL preview (for text messages)"},"type":{"type":"string","enum":["text","image","audio","video","document","location","contacts","template","sticker"]},"text":{"type":"object","properties":{"body":{"type":"string"}}},"image":{"type":"object","properties":{"link":{"type":"string"},"caption":{"type":"string"}}},"audio":{"type":"object","properties":{"link":{"type":"string"}}},"document":{"type":"object","properties":{"link":{"type":"string"},"caption":{"type":"string"},"filename":{"type":"string"}}},"location":{"type":"object","properties":{"latitude":{"type":"string"},"longitude":{"type":"string"},"name":{"type":"string"},"address":{"type":"string"}}},"contacts":{"type":"array","items":{"$ref":"#/components/schemas/ContactCard"}},"template":{"$ref":"#/components/schemas/TemplateMessagePayload"}}},"ContactCard":{"type":"object","properties":{"addresses":{"type":"array","items":{"type":"object","properties":{"street":{"type":"string"},"city":{"type":"string"},"state":{"type":"string"},"zip":{"type":"string"},"country":{"type":"string"},"country_code":{"type":"string"},"type":{"type":"string","enum":["HOME","WORK"]}}}},"birthday":{"type":"string"},"emails":{"type":"array","items":{"type":"object","properties":{"email":{"type":"string"},"type":{"type":"string","enum":["HOME","WORK"]}}}},"name":{"type":"object","properties":{"formatted_name":{"type":"string"},"first_name":{"type":"string"},"last_name":{"type":"string"},"middle_name":{"type":"string"},"suffix":{"type":"string"},"prefix":{"type":"string"}}},"org":{"type":"object","properties":{"company":{"type":"string"},"department":{"type":"string"},"title":{"type":"string"}}},"phones":{"type":"array","items":{"type":"object","properties":{"phone":{"type":"string"},"wa_id":{"type":"string"},"type":{"type":"string","enum":["HOME","WORK"]}}}},"urls":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string"},"type":{"type":"string","enum":["HOME","WORK"]}}}}}},"TemplateMessagePayload":{"type":"object","required":["name","language"],"properties":{"name":{"type":"string"},"language":{"type":"object","properties":{"code":{"type":"string"},"policy":{"type":"string","enum":["deterministic"]}}},"components":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["header","body","button"]},"parameters":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["text","image","document","video","currency","date_time"]},"text":{"type":"string"}}}}}}}}},"SendMessageResponse":{"type":"object","properties":{"messaging_product":{"type":"string"},"contacts":{"type":"array","items":{"type":"object","properties":{"input":{"type":"string"},"wa_id":{"type":"string"}}}},"messages":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"}}}}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}},"responses":{"BadRequest":{"description":"Bad Request – invalid parameters or body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/messages":{"post":{"tags":["Messages"],"operationId":"sendMessage","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendMessageRequest"}}}},"responses":{"200":{"description":"Message sent successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendMessageResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://b2chat.gitbook.io/b2chat-api-mensajeria-whatsapp/nuestros-servicios/mensajes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
