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:
@@ -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}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user