02-ago: [proyecto] vigilancia - notificacion personalizada por Telegram a destinatarios + aviso Discord (DM+TTS) a Carolina/Ines segun persona detectada

This commit is contained in:
minguezsanzjuanjose
2026-08-02 13:53:38 +02:00
parent fa44dcc943
commit 8215f21773
5 changed files with 126 additions and 7 deletions

View File

@@ -6,9 +6,10 @@ 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")
def enviar_telegram(ruta_imagen: str, texto: str, chat_id=None):
chat_id = chat_id or config.TELEGRAM_CHAT_ID
if not config.TELEGRAM_TOKEN or not chat_id:
print("[Telegram] Falta TELEGRAM_TOKEN o chat_id")
return
url = f"https://api.telegram.org/bot{config.TELEGRAM_TOKEN}/sendPhoto"
@@ -16,12 +17,31 @@ def enviar_telegram(ruta_imagen: str, texto: str):
with open(ruta_imagen, "rb") as f:
r = requests.post(
url,
data={"chat_id": config.TELEGRAM_CHAT_ID, "caption": texto},
data={"chat_id": chat_id, "caption": texto},
files={"photo": f},
timeout=10,
)
if not r.ok:
print(f"[Telegram] Error {r.status_code}: {r.text}")
print(f"[Telegram] Error {r.status_code}: {r.text[:200]}")
except Exception as e:
print(f"[Telegram] Excepción al enviar: {e}")
def enviar_texto_telegram(texto: str, chat_id=None):
chat_id = chat_id or config.TELEGRAM_CHAT_ID
if not config.TELEGRAM_TOKEN or not chat_id:
print("[Telegram] Falta TELEGRAM_TOKEN o chat_id")
return
url = f"https://api.telegram.org/bot{config.TELEGRAM_TOKEN}/sendMessage"
try:
r = requests.post(
url,
data={"chat_id": chat_id, "text": texto, "parse_mode": "HTML"},
timeout=10,
)
if not r.ok:
print(f"[Telegram] Error {r.status_code}: {r.text[:200]}")
except Exception as e:
print(f"[Telegram] Excepción al enviar: {e}")