first push
This commit is contained in:
0
notification/najva/__init__.py
Normal file
0
notification/najva/__init__.py
Normal file
17
notification/najva/get_segments_detail.py
Normal file
17
notification/najva/get_segments_detail.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.http.response import JsonResponse
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def get_segments(request):
|
||||
url = "https://app.najva.com/api/v1/websites/65b3a75a-d634-48c5-824f-c80c703534af/segments/"
|
||||
|
||||
headers = {
|
||||
'content-type': "application/json",
|
||||
'authorization': "Token 982c17c1d460fec1eef6270c7d6550e3b9b33d2d",
|
||||
'cache-control': "no-cache",
|
||||
}
|
||||
|
||||
response = requests.request('GET', url=url, headers=headers)
|
||||
resp = json.loads(response.text.encode('utf8'))
|
||||
return JsonResponse(resp, safe=False)
|
||||
75
notification/najva/send_notif_to_segments.py
Normal file
75
notification/najva/send_notif_to_segments.py
Normal file
@@ -0,0 +1,75 @@
|
||||
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
|
||||
Reference in New Issue
Block a user