54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import os
|
|
import subprocess
|
|
|
|
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 config.ALEXA_NOTIFY_SCRIPT:
|
|
env = os.environ.copy()
|
|
if config.VOICEMONKEY_TOKEN:
|
|
env["VOICEMONKEY_TOKEN"] = config.VOICEMONKEY_TOKEN
|
|
if config.VOICEMONKEY_DEVICE:
|
|
env["VOICEMONKEY_DEVICE"] = config.VOICEMONKEY_DEVICE
|
|
try:
|
|
r = subprocess.run(
|
|
[config.ALEXA_NODE, config.ALEXA_NOTIFY_SCRIPT, texto],
|
|
env=env, timeout=15, capture_output=True, text=True,
|
|
)
|
|
if r.returncode != 0:
|
|
print(f"[Alexa] Error middleware: {r.stderr[:200]}")
|
|
except Exception as e:
|
|
print(f"[Alexa] Excepción lanzando middleware: {e}")
|
|
return
|
|
|
|
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}")
|