add notification and send notification
This commit is contained in:
8
core/apps/notifications/utils/notify_user.py
Normal file
8
core/apps/notifications/utils/notify_user.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from core.apps.notifications.models import Notification
|
||||
from core.apps.notifications.utils.send_notification import send_notification
|
||||
|
||||
|
||||
def notify_user(user, title, body):
|
||||
tokens = Notification.objects.filter(user=user)
|
||||
for token in tokens:
|
||||
send_notification(token.token, title, body)
|
||||
16
core/apps/notifications/utils/send_notification.py
Normal file
16
core/apps/notifications/utils/send_notification.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import requests
|
||||
|
||||
def send_notification(token, title, body, data=None):
|
||||
message = {
|
||||
"to": token,
|
||||
"sound": "default",
|
||||
"title": title,
|
||||
"body": body,
|
||||
"data": data or {},
|
||||
}
|
||||
response = requests.post(
|
||||
"https://exp.host/--/api/v2/push/send",
|
||||
json=message,
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user