summaryrefslogtreecommitdiff
path: root/backend/notif.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/notif.py')
-rw-r--r--backend/notif.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/backend/notif.py b/backend/notif.py
index 57ccc23..eb25793 100644
--- a/backend/notif.py
+++ b/backend/notif.py
@@ -3,6 +3,7 @@ import sqlite3
from pywebpush import webpush
from dotenv import load_dotenv
from os import getenv
+import json
class PushSubscriptionData(BaseModel):
endpoint: str
@@ -37,7 +38,7 @@ def subscribe(data: PushSubscriptionData):
VALUES (?, ?, ?)""", (data.endpoint, data.keys["p256dh"], data.keys["auth"]))
conn.commit()
- cursor.execute("SELECT * FROM subscriptions");
+ cursor.execute("SELECT * FROM subscriptions")
result = cursor.fetchall()
for row in result:
@@ -48,8 +49,8 @@ def subscribe(data: PushSubscriptionData):
# --- send notification
# ---- not used yet
-def send_notification(endpoint: str):
- cursor.execute("SELECT * FROM subscriptions WHERE endpoint = ?", (endpoint,))
+def send_notification(endpoint: str, notification_payload: object):
+ cursor.execute(f"""SELECT * FROM subscriptions WHERE endpoint = \"{endpoint}\"""")
row = cursor.fetchall()[0]
print(row)
@@ -64,16 +65,12 @@ def send_notification(endpoint: str):
try:
webpush(
subscription_info=subscription_info,
- data="""
- {
- "title": "Hello, world!",
- "body": "Hello, Victoria Hall!"
- }
- """,
+ data=json.dumps(notification_payload),
vapid_private_key=PRIVATE_VAPID_KEY,
vapid_claims={
"sub": "mailto:dev@altafcreator.com",
},
+ headers={"Urgency": "high"}
)
except Exception as exception:
print(exception)