From 7d3c449c16ba89858b157ce887527ce1de21aae8 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Fri, 16 Feb 2024 19:47:22 +0100 Subject: [PATCH] fix: message title --- client/dispatch-query.py | 16 +++++++++------- server/interface.py | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/client/dispatch-query.py b/client/dispatch-query.py index 8c93d66..b192ab5 100755 --- a/client/dispatch-query.py +++ b/client/dispatch-query.py @@ -46,7 +46,7 @@ def ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, username): print(r.text) return r.json().get("topic") -def ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass): +def ntfy_send(dispatch_uuid, user_topic, title, message, ntfy_push_target, ntfy_user, ntfy_pass): '''Send message via NTFY topic''' if not user_topic: @@ -57,13 +57,13 @@ def ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, n # build message # payload = { - "topic" : user_topic or "test", #TODO fix topic + "topic" : user_topic, "message" : message, - "title" : "Atlantis Notify", + "title" : title or "Atlantis Notify", #"tags" : [], - #"priority" : 4, + "priority" : 4, #"attach" : None, - #"click" : None, + "click" : "https://vid.pr0gramm.com/2022/11/06/ed66c8c5a9cd1a3b.mp4", #"actions" : [] } @@ -143,7 +143,7 @@ if __name__ == "__main__": smtp_pass = args.smtp_pass or os.environ.get("SMTP_PASS") # request dispatches # - response = requests.get(args.dispatch_server + "/get-dispatch?method=all", auth=AUTH) + response = requests.get(args.dispatch_server + "/get-dispatch?method=all&timeout=0", auth=AUTH) # check status # if response.status_code == HTTP_NOT_FOUND: @@ -165,6 +165,7 @@ if __name__ == "__main__": dispatch_uuid = entry["uuid"] method = entry["method"] message = entry["message"] + title = entry.get("title") # method dependent fields # phone = entry.get("phone") @@ -175,7 +176,8 @@ if __name__ == "__main__": pass elif method == "ntfy": user_topic = ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, user) - ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass) + ntfy_send(dispatch_uuid, user_topic, title, message, + ntfy_push_target, ntfy_user, ntfy_pass) elif method == "email": email_send(dispatch_uuid, email_address, message, smtp_target, smtp_user, smtp_pass) elif method == "debug": diff --git a/server/interface.py b/server/interface.py index 44b6525..2f4dcff 100755 --- a/server/interface.py +++ b/server/interface.py @@ -192,6 +192,7 @@ def smart_send_to_clients(): users = instructions.get("users") groups = instructions.get("groups") message = instructions.get("msg") + title = instructions.get("title") method = instructions.get("method") # allow single use string instead of array # @@ -212,11 +213,11 @@ def smart_send_to_clients(): else: persons = ldaptools.select_targets(users, groups, app.config["LDAP_ARGS"]) - dispatch_secrets = save_in_dispatch_queue(persons, message, method) + dispatch_secrets = save_in_dispatch_queue(persons, title, message, method) return flask.jsonify(dispatch_secrets) -def save_in_dispatch_queue(persons, message, method): +def save_in_dispatch_queue(persons, title, message, method): dispatch_secrets = [] @@ -237,6 +238,7 @@ def save_in_dispatch_queue(persons, message, method): method=method or master_method, timestamp=datetime.datetime.now().timestamp(), dispatch_secret=dispatch_secret, + title=title, message=message) db.session.merge(obj)