feat(notify): add telegram alerts for blocked/failed queue tasks

This commit is contained in:
Prime Backup Bot
2026-03-11 20:27:20 +00:00
parent 7d84c9bbd6
commit 29fa11cce1
3 changed files with 35 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
from __future__ import annotations
import os
import urllib.parse
import urllib.request
def send_telegram(text: str) -> bool:
token = os.getenv('TELEGRAM_BOT_TOKEN', '').strip()
chat_id = os.getenv('TELEGRAM_CHAT_ID', '').strip()
if not token or not chat_id:
return False
url = f"https://api.telegram.org/bot{token}/sendMessage"
data = urllib.parse.urlencode({
'chat_id': chat_id,
'text': text,
'disable_web_page_preview': 'true'
}).encode()
req = urllib.request.Request(url, data=data, method='POST')
try:
with urllib.request.urlopen(req, timeout=12) as resp:
return 200 <= resp.status < 300
except Exception:
return False