02-ago: [proyecto] Sistema vigilancia Tapo con deteccion movimiento/persona + notificacion Telegram/Alexa
This commit is contained in:
33
vigilancia/notificador.py
Normal file
33
vigilancia/notificador.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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}")
|
||||
Reference in New Issue
Block a user