← Volver a TelegramController

📨 Mensajes de Prueba

Endpoints para envío de diferentes tipos de mensajes de prueba a través de Telegram

Descripción General

Los endpoints de Mensajes de Prueba permiten enviar diferentes tipos de mensajes a través de Telegram para verificar la integración y probar el sistema de notificaciones. Estos endpoints son útiles para validar la configuración y el funcionamiento del servicio.

🎯 Tipos de Mensajes Disponibles

  • Mensajes Informativos: Notificaciones generales y de estado
  • Mensajes de Error: Alertas de errores y problemas
  • Mensajes de Éxito: Confirmaciones de operaciones exitosas
  • Formato Específico: Cada tipo tiene su propio formato y estilo
  • Modo Producción: Solo funcionan en modo producción (no DEBUG)

Endpoints Disponibles

POST /api/telegram/test-info

Envía un mensaje informativo de prueba. Este endpoint permite enviar mensajes informativos para verificar la integración con Telegram.
Body (JSON):
"This is a test info message from RestMaster API"
200 OK - Mensaje Enviado
Mensaje informativo enviado exitosamente
{ "success": true, "message": "Info message sent successfully", "timestamp": "2024-01-15T10:30:00Z" }
400 Bad Request - Error de Envío
Error al enviar el mensaje informativo
{ "success": false, "message": "Failed to send info message", "timestamp": "2024-01-15T10:30:00Z" }

POST /api/telegram/test-error

Envía un mensaje de error de prueba. Este endpoint permite enviar mensajes de error para verificar las notificaciones de alerta.
Body (JSON):
"This is a test error message from RestMaster API"
200 OK - Mensaje Enviado
Mensaje de error enviado exitosamente
{ "success": true, "message": "Error message sent successfully", "timestamp": "2024-01-15T10:30:00Z" }
400 Bad Request - Error de Envío
Error al enviar el mensaje de error
{ "success": false, "message": "Failed to send error message", "timestamp": "2024-01-15T10:30:00Z" }

POST /api/telegram/test-success

Envía un mensaje de éxito de prueba. Este endpoint permite enviar mensajes de éxito para verificar las notificaciones de confirmación.
Body (JSON):
"This is a test success message from RestMaster API"
200 OK - Mensaje Enviado
Mensaje de éxito enviado exitosamente
{ "success": true, "message": "Success message sent successfully", "timestamp": "2024-01-15T10:30:00Z" }
400 Bad Request - Error de Envío
Error al enviar el mensaje de éxito
{ "success": false, "message": "Failed to send success message", "timestamp": "2024-01-15T10:30:00Z" }

Ejemplos de Uso

🔧 Ejemplo con curl - Mensaje Informativo

curl -X POST \ 'http://localhost:1379/api/telegram/test-info' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '"This is a test info message from RestMaster API"'

🔧 Ejemplo con curl - Mensaje de Error

curl -X POST \ 'http://localhost:1379/api/telegram/test-error' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '"This is a test error message from RestMaster API"'

🔧 Ejemplo con curl - Mensaje de Éxito

curl -X POST \ 'http://localhost:1379/api/telegram/test-success' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '"This is a test success message from RestMaster API"'

🔧 Ejemplo con JavaScript

// Mensaje informativo fetch('/api/telegram/test-info', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify('Test info message') }) .then(response => response.json()) .then(data => console.log(data)); // Mensaje de error fetch('/api/telegram/test-error', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify('Test error message') }) .then(response => response.json()) .then(data => console.log(data)); // Mensaje de éxito fetch('/api/telegram/test-success', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify('Test success message') }) .then(response => response.json()) .then(data => console.log(data));

Servicios Utilizados

ITelegramService - Métodos de Envío:
  • SendMessageAsync(string): Envía mensaje informativo
  • SendErrorMessageAsync(string): Envía mensaje de error
  • SendSuccessMessageAsync(string): Envía mensaje de éxito

📊 Diferencias entre Tipos de Mensaje

  • Mensajes Informativos: Formato estándar para notificaciones generales
  • Mensajes de Error: Formato especial para alertas de errores
  • Mensajes de Éxito: Formato especial para confirmaciones

Modelos de Respuesta

Respuesta de Éxito - Objeto Anónimo:
  • Success (bool): true si el mensaje se envió correctamente
  • Message (string): Mensaje de confirmación
  • Timestamp (DateTime): Marca de tiempo del envío
Respuesta de Error - Objeto Anónimo:
  • Success (bool): false si el mensaje no se pudo enviar
  • Message (string): Mensaje de error
  • Timestamp (DateTime): Marca de tiempo del intento

Casos de Uso

🎯 Escenarios de Prueba

  • Verificación de Configuración: Probar que la integración funciona
  • Pruebas de Formato: Verificar el formato de cada tipo de mensaje
  • Validación de Conectividad: Comprobar conectividad con Telegram
  • Pruebas de Usuario: Permitir a usuarios probar notificaciones
  • Debugging: Diagnosticar problemas de configuración

🔍 Ejemplos de Uso

  • Prueba Inicial: Verificar configuración después de setup
  • Pruebas Periódicas: Verificar funcionamiento regular
  • Pruebas de Usuario: Permitir a administradores probar notificaciones
  • Validación de Formato: Verificar que los mensajes se muestran correctamente
  • Pruebas de Conectividad: Diagnosticar problemas de red

Consideraciones Importantes

⚠️ Modo de Producción

  • Estos endpoints solo funcionan en modo producción (no DEBUG)
  • En modo DEBUG, los endpoints pueden no estar disponibles
  • Se requiere configuración completa del servicio Telegram
  • Los mensajes se envían al chat configurado en el servicio

📋 Requisitos Previos

  • Configuración del Bot: Bot de Telegram configurado y activo
  • Token Válido: Token del bot configurado en el servicio
  • Chat ID: ID del chat donde se enviarán los mensajes
  • Conectividad: Acceso a la API de Telegram
  • Permisos: El bot debe tener permisos para enviar mensajes