Files
biblioteca_conocimiento_lab…/vigilancia/notificador.py

34 lines
992 B
Python

import requests
import config
def enviar_telegram(ruta_imagen: str, texto: str):
if not config.TELEGRAM_TOKEN or not config.TELEGRAM_CHAT_ID:
print("[Telegram] Falta TELEGRAM_TOKEN o TELEGRAM_CHAT_ID")
return
url = f"https://api.telegram.org/bot{config.TELEGRAM_TOKEN}/sendPhoto"
try:
with open(ruta_imagen, "rb") as f:
r = requests.post(
url,
data={"chat_id": config.TELEGRAM_CHAT_ID, "caption": texto},
files={"photo": f},
timeout=10,
)
if not r.ok:
print(f"[Telegram] Error {r.status_code}: {r.text}")
except Exception as e:
print(f"[Telegram] Excepción al enviar: {e}")
def disparar_webhook_alexa(texto: str):
if not config.WEBHOOK_ALEXA:
return
try:
requests.post(config.WEBHOOK_ALEXA, json={"mensaje": texto}, timeout=5)
except Exception as e:
print(f"[Webhook Alexa] Excepción: {e}")