Created
January 16, 2025 16:02
-
-
Save Larswa/aed175d8eb3f9809df538efab5931ee1 to your computer and use it in GitHub Desktop.
Prusa Connect Discord to Pushover webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from flask import Flask, request | |
# Pushover Credentials (Replace with your real credentials) | |
PUSHOVER_USER_KEY = "uboq658g2h4yeu72p4thxfurmu3wkj" | |
PUSHOVER_API_TOKEN = "atsrka2kwa2dc1a9u5xpas36znsn29" | |
def discord_to_pushover(request): | |
"""Handles Discord webhooks from Prusa Connect and forwards to Pushover.""" | |
try: | |
data = request.get_json() | |
if not data: | |
return "No JSON payload received", 400 | |
# Extract important details | |
content = data.get("content", "No content provided") | |
embeds = data.get("embeds", []) | |
# Default values | |
event_title = "Prusa Event" | |
event_details = "No details available." | |
if embeds and isinstance(embeds, list) and len(embeds) > 0: | |
event_title = embeds[0].get("title", event_title) | |
event_details = embeds[0].get("description", event_details) | |
# Construct Pushover message | |
message = f"📢 {event_title}\n{event_details}\n🔔 {content}" | |
# Send notification to Pushover | |
pushover_payload = { | |
"token": PUSHOVER_API_TOKEN, | |
"user": PUSHOVER_USER_KEY, | |
"message": message, | |
} | |
pushover_response = requests.post("https://api.pushover.net/1/messages.json", data=pushover_payload) | |
if pushover_response.status_code == 200: | |
return "Notification Sent!", 200 | |
else: | |
return f"Failed to send Pushover notification: {pushover_response.text}", 500 | |
except Exception as e: | |
return f"Error processing webhook: {str(e)}", 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==2.2.5 | |
requests==2.31.0 | |
werkzeug==2.2.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment