Implement custom notification settings
This commit is contained in:
@@ -592,12 +592,12 @@ def execute_strategy(callback, strategy, func):
|
||||
new_trade.save()
|
||||
else:
|
||||
info = new_trade.post()
|
||||
print("INFO", info)
|
||||
log.debug(f"Posted trade: {info}")
|
||||
|
||||
# Send notification with limited number of fields
|
||||
wanted_fields = ["requestID", "type", "symbol", "units", "reason"]
|
||||
sendmsg(
|
||||
user,
|
||||
", ".join([str(v) for k, v in info.items() if k in wanted_fields]),
|
||||
title=f"{direction} {amount_rounded} on {symbol}",
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
from core.util import logs
|
||||
|
||||
@@ -8,7 +7,8 @@ NTFY_URL = "https://ntfy.sh"
|
||||
log = logs.get_logger(__name__)
|
||||
|
||||
|
||||
def sendmsg(msg, title=None, priority=None, tags=None):
|
||||
# Actual function to send a message to a topic
|
||||
def _sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
||||
headers = {"Title": "Fisk"}
|
||||
if title:
|
||||
headers["Title"] = title
|
||||
@@ -17,7 +17,24 @@ def sendmsg(msg, title=None, priority=None, tags=None):
|
||||
if tags:
|
||||
headers["Tags"] = tags
|
||||
requests.post(
|
||||
f"{NTFY_URL}/{settings.NOTIFY_TOPIC}",
|
||||
f"{url}/{topic}",
|
||||
data=msg,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
|
||||
# Sendmsg helper to send a message to a user's notification settings
|
||||
def sendmsg(user, *args, **kwargs):
|
||||
notification_settings = user.get_notification_settings()
|
||||
if notification_settings.ntfy_url is None:
|
||||
url = NTFY_URL
|
||||
else:
|
||||
url = notification_settings.ntfy_url
|
||||
|
||||
if notification_settings.ntfy_topic is None:
|
||||
# No topic set, so don't send
|
||||
return
|
||||
else:
|
||||
topic = notification_settings.ntfy_topic
|
||||
|
||||
_sendmsg(*args, **kwargs, url=url, topic=topic)
|
||||
|
||||
Reference in New Issue
Block a user