76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
from django.http.response import JsonResponse
|
|
from datetime import datetime, timezone, timedelta
|
|
import requests
|
|
import json
|
|
|
|
|
|
def send_notification_to_all_segments(
|
|
title=None,
|
|
body=None,
|
|
content=None,
|
|
icon=None,
|
|
image=None,
|
|
segments_include=None,
|
|
segments_exclude=None,
|
|
):
|
|
url = "https://app.najva.com/api/v1/notifications/"
|
|
|
|
payload = {
|
|
"api_key": "65b3a75a-d634-48c5-824f-c80c703534af",
|
|
"title": "title",
|
|
"body": "body",
|
|
"priority": "high",
|
|
"onclick_action": "open-link",
|
|
"url": "https://imedstores.ir/",
|
|
"content": "content",
|
|
"icon": "",
|
|
"image": "",
|
|
# "json": "{"key":"value"}",
|
|
"sent_time": datetime.now() + timedelta(minutes=1),
|
|
"segments_include": [],
|
|
"segments_exclude": [],
|
|
"one_signal_enabled": False,
|
|
"one_signal_accounts": []
|
|
}
|
|
headers = {
|
|
'authorization': "Token 982c17c1d460fec1eef6270c7d6550e3b9b33d2d",
|
|
'content-type': "application/json",
|
|
'cache-control': "no-cache",
|
|
}
|
|
|
|
response = requests.request("POST", url, data=json.dumps(payload, default=str), headers=headers)
|
|
resp = json.loads(response.text.encode('utf-8'))
|
|
return resp
|
|
|
|
|
|
def send_notification_to_specific_segment(
|
|
title="سامانه سبحان طیور",
|
|
body="خوش آمدید",
|
|
content="سامانه مدیریت درخواست های مرغداران",
|
|
icon="https://user-image-gallery.s3.ir-thr-at1.arvanstorage.com/1WGPTMFND3TREWD.jpg",
|
|
image="https://user-image-gallery.s3.ir-thr-at1.arvanstorage.com/1WGPTMFND3TREWD.jpg",
|
|
subscriber_tokens=None,
|
|
):
|
|
url = "https://app.najva.com/notification/api/v1/notifications/"
|
|
payload = {
|
|
"api_key": "65b3a75a-d634-48c5-824f-c80c703534af",
|
|
"subscriber_tokens": subscriber_tokens,
|
|
"title": title,
|
|
"body": body,
|
|
"onclick_action": "open-link",
|
|
"url": "https://imedstores.ir/",
|
|
"content": content,
|
|
"icon": icon,
|
|
"image": image,
|
|
"sent_time": datetime.now() + timedelta(minutes=3),
|
|
}
|
|
headers = {
|
|
'authorization': "Token 982c17c1d460fec1eef6270c7d6550e3b9b33d2d",
|
|
'content-type': "application/json",
|
|
'cache-control': "no-cache",
|
|
}
|
|
|
|
response = requests.request("POST", url, data=json.dumps(payload, default=str), headers=headers)
|
|
resp = json.loads(response.text.encode('utf-8'))
|
|
return resp
|