0.11.20 push w link

This commit is contained in:
SDE
2024-01-16 16:53:01 +03:00
parent 793d283d97
commit 87fbe7852c
9 changed files with 118 additions and 35 deletions

View File

@@ -6,6 +6,7 @@ from webpush import send_user_notification
import json
from django.shortcuts import render, get_object_or_404
from django.conf import settings
from django.utils.translation import gettext as _
def get_key_Dict():
@@ -16,7 +17,7 @@ def get_key_Dict():
}
return Dict
def send_push(user, title, text, img=None):
def send_push(user, title, text, url=None, button_name=None, img=None):
try:
# body = request.body
# data = json.loads(body)
@@ -28,8 +29,17 @@ def send_push(user, title, text, img=None):
# user = get_object_or_404(User, pk=user_id)
Dict = {
'head': title,
'body': text
'body': text,
}
if url:
Dict['url'] = url
if button_name:
Dict['button_name'] = button_name
else:
Dict['button_name'] = _('Перейти'),
if img:
Dict['img'] = img
# payload = {'head': data['head'], 'body': data['body']}
send_user_notification(user=user, payload=Dict, ttl=1000)