✨ added notification API
This commit is contained in:
parent
8249ac0355
commit
d769f9f31f
3 changed files with 24 additions and 1 deletions
|
@ -5,3 +5,7 @@
|
||||||
- `email` : Personal Mail
|
- `email` : Personal Mail
|
||||||
- `secret_key` : Secret Key for Flask
|
- `secret_key` : Secret Key for Flask
|
||||||
- `xmr_address` : Monero Receive Address
|
- `xmr_address` : Monero Receive Address
|
||||||
|
- `notify` : Notification Object
|
||||||
|
- - `gotify`: Gotify Object
|
||||||
|
- - - `token` : Gotify Token
|
||||||
|
- - - `host` : Gotify Host/Domain name
|
|
@ -1,3 +1,4 @@
|
||||||
Flask
|
Flask
|
||||||
gnupg
|
gnupg
|
||||||
|
requests
|
||||||
git+https://github.com/jmarya/htmlpy#egg=htmlpy
|
git+https://github.com/jmarya/htmlpy#egg=htmlpy
|
18
src/index.py
18
src/index.py
|
@ -4,6 +4,7 @@ from config import CONFIG
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
import requests
|
||||||
import gnupg
|
import gnupg
|
||||||
|
|
||||||
main_pages = Blueprint("main", __name__)
|
main_pages = Blueprint("main", __name__)
|
||||||
|
@ -38,6 +39,22 @@ def save_message(msg, name=""):
|
||||||
f.write(msg)
|
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
|
# Message Sending Page
|
||||||
@main_pages.route("/message", methods=["GET", "POST"])
|
@main_pages.route("/message", methods=["GET", "POST"])
|
||||||
def send_message():
|
def send_message():
|
||||||
|
@ -48,6 +65,7 @@ def send_message():
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
cipher = encrypt(msg)
|
cipher = encrypt(msg)
|
||||||
save_message(cipher, name)
|
save_message(cipher, name)
|
||||||
|
notify(f"New Message from {name}")
|
||||||
return redirect(request.url_root.replace("http", "https"))
|
return redirect(request.url_root.replace("http", "https"))
|
||||||
else:
|
else:
|
||||||
# Return Message Form
|
# Return Message Form
|
||||||
|
|
Loading…
Add table
Reference in a new issue