test notification
This commit is contained in:
parent
950da26958
commit
c3ab41dd6a
@ -218,3 +218,26 @@ def send_expiry_notifications_route(username: str, password: str) -> Response:
|
||||
from ktvmanager.account_checker import send_expiry_notifications
|
||||
send_expiry_notifications()
|
||||
return jsonify({"message": "Expiry notifications sent."})
|
||||
|
||||
|
||||
@api_blueprint.route("/send-test-notification", methods=["POST"])
|
||||
@requires_basic_auth
|
||||
def send_test_notification_route(username: str, password: str) -> Response:
|
||||
"""Sends a test push notification to the user."""
|
||||
user_id = get_user_id_from_username(username)
|
||||
if not user_id:
|
||||
return jsonify({"message": "User not found"}), 404
|
||||
|
||||
subscriptions = get_push_subscriptions(user_id)
|
||||
if not subscriptions:
|
||||
return jsonify({"message": "No push subscriptions found for this user."}), 404
|
||||
|
||||
message_body = json.dumps({"title": "Test Notification", "body": "This is a test notification."})
|
||||
|
||||
for sub in subscriptions:
|
||||
try:
|
||||
send_notification(json.loads(sub['subscription_json']), message_body)
|
||||
except Exception as e:
|
||||
print(f"Error sending notification to subscription ID {sub.get('id', 'N/A')}: {e}")
|
||||
|
||||
return jsonify({"message": f"Test notification sent to {len(subscriptions)} subscription(s)."})
|
Loading…
x
Reference in New Issue
Block a user