# API de Mensajes

Se requiere el token de canal para acceder a este recurso de API.\
Los tokens se pueden generar usando el icono de llave, junto al canal deseado en Configuración.

## Peticiones <a href="#requests" id="requests"></a>

La API de contactos se compone de varios tipos de solicitudes:

* [Enviar mensajes de texto](broken://pages/-MEqYdZH8PqA0tcXsSq-#send-text-request)
* [Enviar datos adjuntos](broken://pages/-MEqYdZH8PqA0tcXsSq-#send-attachment-request)
* [Enviar texto con respuestas rápidas](broken://pages/-MEqYdZH8PqA0tcXsSq-#send-text-with-quick-replies-request)

### Enviar solicitud de texto <a href="#send-text-request" id="send-text-request"></a>

Esta solicitud envía un mensaje de texto directamente al contacto según se define en el punto final.

```
POST /v1/message/sendContent/{contactId}
```

#### Ejemplo de solicitud de texto POST <a href="#sample-post-text-request" id="sample-post-text-request"></a>

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	{
  		"type" : "text",
  		"text" : "Hi there"
  	}
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200" id="response-success-http-status-200"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

{% hint style="info" %}
Tenga en cuenta que en el caso del canal Viber, debido a una cierta limitación, la ID de contacto debe proporcionarse en un formato codificado en **Base64**.
{% endhint %}

### Enviar solicitud de adjunto <a href="#send-attachment-request" id="send-attachment-request"></a>

Esta solicitud envía un archivo adjunto en forma de URL directamente al contacto según se define en el punto final. El archivo puede ser imagen, video, audio o archivo.

```
POST /v1/message/sendContent/{contactId}
```

#### Solicitud de envío de imagen POST de muestra <a href="#sample-post-send-image-request" id="sample-post-send-image-request"></a>

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	{
  		"type" : "image",
  		"url" : "http://abc.com"
  	}
  	}
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200-1" id="response-success-http-status-200-1"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

#### Solicitud de envío de video POST de muestra <a href="#sample-post-send-video-request" id="sample-post-send-video-request"></a>

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	{
  		"type" : "video",
  		"url" : "http://abc.com"
  	}
  	}
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200-2" id="response-success-http-status-200-2"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

#### Ejemplo de solicitud de envío de audio POST <a href="#sample-post-send-audio-request" id="sample-post-send-audio-request"></a>

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	{
  		"type" : "audio",
  		"url" : "http://abc.com"
  	}
  	}
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200-3" id="response-success-http-status-200-3"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

#### Ejemplo de solicitud de envío de archivos POST <a href="#sample-post-send-file-request" id="sample-post-send-file-request"></a>

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	{
  		"type" : "audio",
  		"url" : "http://abc.com"
  	}
  	}
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200-4" id="response-success-http-status-200-4"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

### Enviar mensaje de texto con solicitud de respuestas rápidas <a href="#send-text-with-quick-replies-request" id="send-text-with-quick-replies-request"></a>

Esta solicitud envía un mensaje de texto con respuestas rápidas para los receptores.

```
curl -X POST \
      https://app.bony.chat/api/v1/message/sendContent/{contactId} \
      -H 'Authorization: Bearer {channel_token}' \
      -H 'Content-Type: application/json' \
      -d '{
  "body": [
  	
    {
      "type":"quick_reply",
    	"title" : "What is you favorite color?",
    	"replies" : ["Black","Blue","Grey","Red"]
    }
    
  ]
}'
```

#### Respuesta: **éxito (estado HTTP → 200)** <a href="#response-success-http-status-200-5" id="response-success-http-status-200-5"></a>

```
    {
      "status": "Success",
      "message": "Message Sent",
      "data": []
  }
```

## ​Códigos de error

### **No autorizado (estado HTTP → 401)** <a href="#unauthorized-http-status-401" id="unauthorized-http-status-401"></a>

```
{
        "status": "error",
        "message": "API Token is invalid.",
        "data": []
    }
```

### **Demasiadas solicitudes (estado HTTP → 429)** <a href="#too-many-requests-http-status-429" id="too-many-requests-http-status-429"></a>

```
   {
      "status": "error",
      "message": "Too many requests",
      "data": []
  }
```

### **Método no permitido** **(estado HTTP → 405)**  <a href="#method-not-allowed-http-status-405" id="method-not-allowed-http-status-405"></a>

```
   {
      "status": "error",
      "message": "405 Method Not Allowed.",
      "data": []
  }
```

### **General (Estado HTTP → 403)** <a href="#general-http-status-403" id="general-http-status-403"></a>

```
  {
      "status": "error",
      "message": "Message String",
      "data": []
  }
```

### **Tipo de archivo incomparable (Estado HTTP → 403)** <a href="#unmatched-file-type-http-status-403" id="unmatched-file-type-http-status-403"></a>

```
  {
      "status": "error",
      "message": "Sorry, Url provided is not an image/audio/video file",
      "data": []
  }
```

### Limitaciones <a href="#limitations" id="limitations"></a>

* Solo se puede enviar un mensaje en una llamada a la API.
* API tiene un límite de velocidad de 25 RPS.
* Se permiten 10 respuestas rápidas de 20 caracteres cada una.
* La encuesta no se cancela de forma predeterminada. debe enviarse explícitamente en la carga útil.`forceCancelSurvey : true`El estado del contacto no se cambiará en la llamada a la API.


---

# 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://docs.bony.chat/api-de-desarolladores/api-de-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.
