✨ added notification API
This commit is contained in:
parent
8249ac0355
commit
d769f9f31f
3 changed files with 24 additions and 1 deletions
18
src/index.py
18
src/index.py
|
@ -4,6 +4,7 @@ from config import CONFIG
|
|||
from os.path import exists
|
||||
import os
|
||||
import datetime
|
||||
import requests
|
||||
import gnupg
|
||||
|
||||
main_pages = Blueprint("main", __name__)
|
||||
|
@ -38,6 +39,22 @@ def save_message(msg, name=""):
|
|||
f.write(msg)
|
||||
|
||||
|
||||
def notify(msg, title=None):
|
||||
try:
|
||||
gotify_notification(msg, title)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def gotify_notification(msg, title=None):
|
||||
token = CONFIG["notify"]["gotify"]["token"]
|
||||
url = CONFIG["notify"]["gotify"]["host"]
|
||||
requests.post(
|
||||
f"https://{url}/message?token={token}",
|
||||
{"title": title, "message": msg, "priority": "5"},
|
||||
)
|
||||
|
||||
|
||||
# Message Sending Page
|
||||
@main_pages.route("/message", methods=["GET", "POST"])
|
||||
def send_message():
|
||||
|
@ -48,6 +65,7 @@ def send_message():
|
|||
if msg is not None:
|
||||
cipher = encrypt(msg)
|
||||
save_message(cipher, name)
|
||||
notify(f"New Message from {name}")
|
||||
return redirect(request.url_root.replace("http", "https"))
|
||||
else:
|
||||
# Return Message Form
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue