mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2025-12-06 06:21:36 +01:00
feat: support dynamic links in msg or link-field
Some checks failed
ci / docker (push) Failing after 17s
Some checks failed
ci / docker (push) Failing after 17s
This commit is contained in:
@@ -54,21 +54,32 @@ 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, title, message, ntfy_push_target, ntfy_user, ntfy_pass):
|
||||
def ntfy_send(dispatch_uuid, user_topic, title, message, link,
|
||||
ntfy_push_target, ntfy_user, ntfy_pass):
|
||||
'''Send message via NTFY topic'''
|
||||
|
||||
# check message for links #
|
||||
if not link:
|
||||
pattern = r"https:\/\/[^\s]+"
|
||||
match = re.search(pattern, text)
|
||||
if match:
|
||||
link = match.group(0)
|
||||
|
||||
# limit message length and title #
|
||||
title = title or ""
|
||||
message = message or ""
|
||||
message = message[:1024]
|
||||
title = title[:512]
|
||||
|
||||
|
||||
if not user_topic:
|
||||
report_failed_dispatch(dispatch_uuid, "No user topic")
|
||||
return
|
||||
|
||||
try:
|
||||
|
||||
|
||||
|
||||
# build message #
|
||||
payload = {
|
||||
"topic" : user_topic,
|
||||
@@ -77,7 +88,7 @@ def ntfy_send(dispatch_uuid, user_topic, title, message, ntfy_push_target, ntfy_
|
||||
#"tags" : [],
|
||||
"priority" : 4,
|
||||
#"attach" : None,
|
||||
"click" : "https://vid.pr0gramm.com/2022/11/06/ed66c8c5a9cd1a3b.mp4",
|
||||
"click" : link,
|
||||
#"actions" : []
|
||||
}
|
||||
|
||||
@@ -190,6 +201,7 @@ if __name__ == "__main__":
|
||||
method = entry["method"]
|
||||
message = entry["message"]
|
||||
title = entry.get("title")
|
||||
link = entry.get("link")
|
||||
|
||||
# method dependent fields #
|
||||
phone = entry.get("phone")
|
||||
@@ -200,7 +212,7 @@ 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, title, message,
|
||||
ntfy_send(dispatch_uuid, user_topic, title, message, link,
|
||||
ntfy_push_target, ntfy_user, ntfy_pass)
|
||||
elif method == "email":
|
||||
email_send(dispatch_uuid, email_address, message, smtp_target,
|
||||
|
||||
Reference in New Issue
Block a user