From 270c94ac93c24a4c78397f321466dafdf28cb676 Mon Sep 17 00:00:00 2001 From: Thies Mueller Date: Sun, 21 Jun 2026 16:40:23 +0200 Subject: [PATCH] add telegram --- app.py | 41 +++++++++++++++++++++++++++++++++++++++++ config.example.yaml | 6 +++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 747e510..41a9187 100644 --- a/app.py +++ b/app.py @@ -11,6 +11,7 @@ SERVER_TOKEN = config["server"]["bearer_token"] APNS2_CONFIG = config["apns2"] FIREBASE_CONFIG = config["firebase"] +TELEGRAM_CONFIG = config["telegram"] PREFIX_MAP = { @@ -86,6 +87,32 @@ def send_to_firebase(notification_type, title, message): "body": response.text } + +def send_to_telegram(notification_type, title, message): + prefix = PREFIX_MAP.get(notification_type, "") + + payload = { + "message": f"{prefix}{title}\n{message}" + } + + headers = { + "X-API-Key": TELEGRAM_CONFIG["api_key"], + "Content-Type": "application/json" + } + + response = requests.post( + TELEGRAM_CONFIG["url"], + json=payload, + headers=headers, + timeout=10 + ) + + return { + "status_code": response.status_code, + "body": response.text + } + + @app.route("/notify", methods=["POST"]) def notify(): if not check_auth(request): @@ -150,6 +177,20 @@ def notify(): "error": str(e) } + try: + telegram_result = send_to_telegram( + notification_type, + title, + message + ) + + results["telegram"] = telegram_result + + except Exception as e: + results["telegram"] = { + "error": str(e) + } + return jsonify({ "success": True, "results": results diff --git a/config.example.yaml b/config.example.yaml index 0f583d9..c552dca 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -7,4 +7,8 @@ apns2: firebase: url: "https://firebase.example.com/push" - bearer_token: "firebase-token" \ No newline at end of file + bearer_token: "firebase-token" + +telegram: + url: "https://telegram.example.com/push" + api_key: "telegram-api-key" \ No newline at end of file