lignarr/Trainer-PPO
0
1import requests2import config3 4def send_telegram_message(message: str):5 """Send a message to the configured Telegram chat."""6 if not config.TELEGRAM_BOT_TOKEN or not config.TELEGRAM_CHAT_ID:7 return8 url = f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}/sendMessage"9 payload = {10 "chat_id": config.TELEGRAM_CHAT_ID,11 "text": message,12 "parse_mode": "HTML"13 }14 try:15 requests.post(url, json=payload, timeout=5)16 except Exception as e:17 print(f"Telegram error: {e}")18 19def send_telegram_document(file_path: str, caption: str = ""):20 """Send a document (like a log or model zip) to Telegram."""21 if not config.TELEGRAM_BOT_TOKEN or not config.TELEGRAM_CHAT_ID:22 return23 url = f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}/sendDocument"24 try:25 with open(file_path, "rb") as f:26 files = {"document": f}27 data = {"chat_id": config.TELEGRAM_CHAT_ID, "caption": caption}28 requests.post(url, data=data, files=files, timeout=15)29 except Exception as e:30 print(f"Telegram document error: {e}")31 