Allow using webhooks for notifications

This commit is contained in:
2023-01-15 18:40:17 +00:00
parent 46c7d96310
commit eb2486afba
7 changed files with 168 additions and 28 deletions

View File

@@ -9,8 +9,6 @@ log = logs.get_logger(__name__)
# Actual function to send a message to a topic
def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
if url is None:
url = NTFY_URL
headers = {"Title": "Fisk"}
if title:
headers["Title"] = title
@@ -32,11 +30,20 @@ def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None)
def sendmsg(user, *args, **kwargs):
notification_settings = user.get_notification_settings()
# No custom topic specified
if "topic" not in kwargs:
if notification_settings.ntfy_topic is None:
# No user topic set either
if notification_settings.topic is None:
# No topic set, so don't send
return
else:
kwargs["topic"] = notification_settings.ntfy_topic
kwargs["topic"] = notification_settings.topic
raw_sendmsg(*args, **kwargs, url=notification_settings.ntfy_url)
if "url" in kwargs:
url = kwargs["url"]
elif notification_settings.url is not None:
url = notification_settings.url
else:
url = NTFY_URL
raw_sendmsg(*args, **kwargs, url=url)