Telegram
Resumen
Sección titulada «Resumen»El provider Telegram permite que tu trabajador digital se comunique mediante bots de Telegram. Soporta:
- Mensajes de texto
- Teclados inline (botones)
- Teclados de respuesta
- Adjuntos de archivos
- Medios (fotos, videos, documentos)
- Chats grupales
Requisitos previos
Sección titulada «Requisitos previos»- Una cuenta de Telegram
- Un bot de Telegram (creado mediante @BotFather)
Configuración
Sección titulada «Configuración»-
Crea un bot de Telegram
Abre Telegram y envía un mensaje a @BotFather:
/newbotSigue las indicaciones:
- Ingresa un nombre para tu bot (por ejemplo, “My Support Bot”)
- Ingresa un nombre de usuario (debe terminar en
bot, por ejemplo, “my_support_bot”)
BotFather te dará un bot token como este:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz -
Configura el provider
Crea o actualiza tu archivo de respuestas:
answers.json {"messaging-telegram": {"enabled": true,"public_base_url": "https://your-domain.ngrok-free.app","bot_token": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"}} -
Ejecuta la configuración
Ventana de terminal gtc setup --answers answers.json ./my-bundle -
Inicia el runtime
Ventana de terminal gtc start ./my-bundle -
Prueba tu bot
Abre Telegram, busca tu bot por nombre de usuario y envíale un mensaje.
Opciones de configuración
Sección titulada «Opciones de configuración»| Opción | Requerido | Descripción |
|---|---|---|
enabled | Sí | Habilita/deshabilita el provider |
public_base_url | Sí | URL pública para el webhook |
bot_token | Sí | Bot token de @BotFather |
api_base_url | No | URL de la API de Telegram (por defecto: https://api.telegram.org) |
Funcionalidades
Sección titulada «Funcionalidades»Mensajes de texto
Sección titulada «Mensajes de texto»- id: reply type: reply config: message: "Hello! How can I help you today?"Formato Markdown
Sección titulada «Formato Markdown»Telegram soporta MarkdownV2:
- id: formatted_reply type: reply config: message: | *Bold* _Italic_ `Code` [Link](https://example.com) parse_mode: MarkdownV2Teclados inline (botones)
Sección titulada «Teclados inline (botones)»- id: ask_action type: reply config: message: "What would you like to do?" buttons: - row: - label: "Get Help" callback_data: "action:help" - label: "Settings" callback_data: "action:settings" - row: - label: "Contact Support" url: "https://support.example.com"Teclados de respuesta
Sección titulada «Teclados de respuesta»- id: ask_choice type: reply config: message: "Choose an option:" reply_keyboard: - ["Option A", "Option B"] - ["Option C", "Cancel"] resize_keyboard: true one_time_keyboard: trueEnviar fotos
Sección titulada «Enviar fotos»- id: send_image type: reply config: photo: url: "https://example.com/image.jpg" caption: "Here's your image!"Enviar documentos
Sección titulada «Enviar documentos»- id: send_file type: reply config: document: url: "https://example.com/report.pdf" filename: "report.pdf" caption: "Your monthly report"Responder a un mensaje específico
Sección titulada «Responder a un mensaje específico»- id: reply_to_message type: reply config: message: "This is a reply to your previous message" reply_to_message_id: "{{original_message_id}}"Manejo de callbacks de botones
Sección titulada «Manejo de callbacks de botones»Cuando un usuario hace clic en un botón de un teclado inline, recibes un callback:
name: handle_callbackversion: "1.0"
nodes: - id: check_action type: branch config: conditions: - expression: "callback_data == 'action:help'" next: show_help - expression: "callback_data == 'action:settings'" next: show_settings default: unknown_action
- id: show_help type: reply config: message: "Here's how I can help..."
- id: show_settings type: reply config: message: "Settings menu..."
- id: unknown_action type: reply config: message: "Unknown action"
triggers: - type: callback_query target: check_actionSoporte para chats grupales
Sección titulada «Soporte para chats grupales»El provider Telegram soporta chats grupales:
tenants: demo: teams: support: channels: telegram-group: provider: messaging-telegram config: chat_id: "-1001234567890" # Group chat IDObtener el ID del chat grupal
Sección titulada «Obtener el ID del chat grupal»- Agrega tu bot al grupo
- Envía un mensaje en el grupo
- Revisa el payload del webhook para ver
chat.id
O usa la API de Telegram:
curl "https://api.telegram.org/bot<TOKEN>/getUpdates"Configuración del webhook
Sección titulada «Configuración del webhook»El flow de configuración configura automáticamente el webhook:
POST https://api.telegram.org/bot<TOKEN>/setWebhook{ "url": "https://your-domain.com/webhook/telegram/{tenant}/{team}", "allowed_updates": ["message", "callback_query"]}Configuración manual del webhook
Sección titulada «Configuración manual del webhook»Si es necesario, configúralo manualmente:
curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{ "url": "https://your-domain.com/webhook/telegram/demo/default", "allowed_updates": ["message", "callback_query"] }'Solución de problemas
Sección titulada «Solución de problemas»El bot no responde
Sección titulada «El bot no responde»-
Revisa el estado del webhook:
Ventana de terminal curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo" -
Verifica que la URL pública sea accesible:
Ventana de terminal curl https://your-domain.ngrok-free.app/health -
Revisa los logs:
Ventana de terminal gtc start ./my-bundle --verbose
Falló el registro del webhook
Sección titulada «Falló el registro del webhook»Error: 401 UnauthorizedVerifica que tu bot token sea correcto y no haya expirado.
No se reciben mensajes
Sección titulada «No se reciben mensajes»- Asegúrate de que el bot haya sido iniciado (el usuario envió
/start) - Comprueba si el bot está en el grupo (para chats grupales)
- Verifica que la URL del webhook coincida con tu URL pública
Rate limiting
Sección titulada «Rate limiting»Telegram tiene límites de velocidad:
- 1 mensaje por segundo por chat
- 30 mensajes por segundo en total
Maneja los límites de velocidad con cuidado:
- id: reply type: reply config: message: "Response" retry_on_429: true max_retries: 3Seguridad
Sección titulada «Seguridad»Seguridad del webhook
Sección titulada «Seguridad del webhook»Telegram envía un token secreto con las solicitudes del webhook. Greentic lo valida automáticamente.
Validación de entrada
Sección titulada «Validación de entrada»Valida siempre la entrada del usuario:
- id: validate type: script config: script: | if message.len() > 4096 { return error("Message too long") } messagePróximos pasos
Sección titulada «Próximos pasos»- Provider de Slack - Agrega integración con Slack
- Guía de Flows - Construye flujos de trabajo complejos
- Buttons and Cards - Elementos de UI enriquecidos