#!/usr/bin/env bash # =============================================================================================================== # notify-telegram.sh - Envía notificaciones a Telegram # Descripción: # Wrapper simple para enviar mensajes a un chat de Telegram. # Requiere TELEGRAM_BOT_TOKEN y TELEGRAM_CHAT_ID como variables # de entorno. # # Uso: # bash notify-telegram.sh "Mensaje de prueba" # # Autor: Área de Tecnología y Desarrollo - CCsoft # =============================================================================================================== set -euo pipefail # ------------------------------------------------------------------------------- # Validación # ------------------------------------------------------------------------------- TELEGRAM_BOT_TOKEN="${TELEGRAM_BOT_TOKEN:-}" TELEGRAM_CHAT_ID="${TELEGRAM_CHAT_ID:-}" MESSAGE="${1:-}" if [[ -z "$TELEGRAM_BOT_TOKEN" ]]; then echo "[ERROR] TELEGRAM_BOT_TOKEN no definido" >&2 exit 1 fi if [[ -z "$TELEGRAM_CHAT_ID" ]]; then echo "[ERROR] TELEGRAM_CHAT_ID no definido" >&2 exit 1 fi if [[ -z "$MESSAGE" ]]; then echo "[ERROR] Debe proporcionar un mensaje como primer argumento" >&2 exit 1 fi # ------------------------------------------------------------------------------- # Envío de mensaje # ------------------------------------------------------------------------------- curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ -d "chat_id=${TELEGRAM_CHAT_ID}" \ -d "text=${MESSAGE}" \ -d "parse_mode=Markdown" > /dev/null echo "[INFO] Mensaje enviado a Telegram"