first push
This commit is contained in:
0
notification/pushe/__init__.py
Normal file
0
notification/pushe/__init__.py
Normal file
3
notification/pushe/constants.py
Normal file
3
notification/pushe/constants.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Obtain token -> https://docs.pushe.co/docs/web-api/authentication
|
||||
|
||||
TOKEN = "YOUR_TOKEN"
|
||||
53
notification/pushe/send_custom_content_notification.py
Normal file
53
notification/pushe/send_custom_content_notification.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=4 sw=4 et
|
||||
|
||||
import requests
|
||||
from notification.pushe.constants import TOKEN
|
||||
|
||||
|
||||
def send_custom_content_notification(data):
|
||||
# set header
|
||||
headers = {"Authorization": "Token " + TOKEN, "Content-Type": "application/json"}
|
||||
|
||||
# Webpush doc -> http://docs.pushe.co/docs/web-api/custom-content-notification/
|
||||
|
||||
data = {
|
||||
"app_ids": [
|
||||
"YOUR_APP_ID",
|
||||
],
|
||||
"data": {
|
||||
"title": "Title",
|
||||
"content": "Content",
|
||||
},
|
||||
"custom_content": {"key1": "value1", "key2": "value2"},
|
||||
}
|
||||
|
||||
# send request
|
||||
response = requests.post(
|
||||
"https://api.pushe.co/v2/messaging/notifications/web/",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
# get status_code and response
|
||||
print("status code => ", response.status_code)
|
||||
print("response => ", response.json())
|
||||
print("==========")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Success!")
|
||||
|
||||
data = response.json()
|
||||
|
||||
# hashed_id just generated for Non-Free plan
|
||||
if data["hashed_id"]:
|
||||
report_url = "https://pushe.co/report?id=%s" % data["hashed_id"]
|
||||
else:
|
||||
report_url = "no report url for your plan"
|
||||
|
||||
notif_id = data["wrapper_id"]
|
||||
print("report_url: %s" % report_url)
|
||||
print("notification id: %s" % notif_id)
|
||||
else:
|
||||
print("failed")
|
||||
pass
|
||||
54
notification/pushe/send_filtered_notification.py
Normal file
54
notification/pushe/send_filtered_notification.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=4 sw=4 et
|
||||
|
||||
|
||||
import requests
|
||||
from notification.pushe.constants import TOKEN
|
||||
|
||||
|
||||
def send_filtered_notification(data):
|
||||
# set header
|
||||
headers = {"Authorization": "Token " + TOKEN, "Content-Type": "application/json"}
|
||||
|
||||
# Webpush doc -> https://docs.pushe.co/docs/web-api/filtered-notification
|
||||
|
||||
data = {
|
||||
"app_ids": [
|
||||
"YOUR_APP_ID",
|
||||
],
|
||||
"data": {
|
||||
"title": "This is a filtered push",
|
||||
"content": "Only users with specified device_id(s) will see this notification.",
|
||||
},
|
||||
"filters": {"device_id": ["DEIVCE_ID_1", "DEVICE_ID_2"]}
|
||||
# additional keywords -> https://docs.pushe.co/docs/web-api/notification-keys
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
"https://api.pushe.co/v2/messaging/notifications/web/",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
print("status code => ", response.status_code)
|
||||
print("response => ", response.json())
|
||||
print("==========")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Success!")
|
||||
|
||||
data = response.json()
|
||||
|
||||
# hashed_id only generated for Non-Free plan
|
||||
if data["hashed_id"]:
|
||||
report_url = "https://pushe.co/report?id=%s" % data["hashed_id"]
|
||||
else:
|
||||
report_url = "no report url for your plan"
|
||||
|
||||
notif_id = data["wrapper_id"]
|
||||
print("report_url: %s" % report_url)
|
||||
print("notification id: %s" % notif_id)
|
||||
else:
|
||||
print("failed")
|
||||
|
||||
pass
|
||||
67
notification/pushe/send_notification_with_action.py
Normal file
67
notification/pushe/send_notification_with_action.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=4 sw=4 et
|
||||
|
||||
import requests
|
||||
from notification.pushe.constants import TOKEN
|
||||
|
||||
|
||||
def send_notification_with_action(data):
|
||||
# set header
|
||||
headers = {"Authorization": "Token " + TOKEN, "Content-Type": "application/json"}
|
||||
|
||||
data = {
|
||||
"app_ids": [
|
||||
"YOUR_APP_ID",
|
||||
],
|
||||
"data": {
|
||||
"title": "Title",
|
||||
"content": "Content",
|
||||
# Actions -> https://docs.pushe.co/docs/web-api/notification-actions
|
||||
"action": {
|
||||
"action_type": "U",
|
||||
"url": "https://pushe.co",
|
||||
},
|
||||
"buttons": [
|
||||
{
|
||||
"btn_content": "YOUR_CONTENT",
|
||||
"btn_action": {"action_type": "U", "url": "https://pushe.co"},
|
||||
"btn_order": 0,
|
||||
},
|
||||
{
|
||||
"btn_content": "YOUR_CONTENT",
|
||||
"btn_action": {"action_type": "U", "url": "https://pushe.co"},
|
||||
"btn_order": 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
# send request
|
||||
response = requests.post(
|
||||
"https://api.pushe.co/v2/messaging/notifications/web/",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
# get status_code and response
|
||||
print("status code => ", response.status_code)
|
||||
print("response => ", response.json())
|
||||
print("==========")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Success!")
|
||||
|
||||
data = response.json()
|
||||
|
||||
# hashed_id only generated for Non-Free plan
|
||||
if data["hashed_id"]:
|
||||
report_url = "https://pushe.co/report?id=%s" % data["hashed_id"]
|
||||
else:
|
||||
report_url = "no report url for your plan"
|
||||
|
||||
notif_id = data["wrapper_id"]
|
||||
print("report_url: %s" % report_url)
|
||||
print("notification id: %s" % notif_id)
|
||||
else:
|
||||
print("failed")
|
||||
pass
|
||||
52
notification/pushe/send_simple_notification.py
Normal file
52
notification/pushe/send_simple_notification.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=4 sw=4 et
|
||||
|
||||
import requests
|
||||
from notification.pushe.constants import TOKEN
|
||||
|
||||
# Webpush doc -> https://docs.pushe.co/docs/web-api/filtered-notification
|
||||
|
||||
|
||||
def send_simple_notification(data):
|
||||
headers = {"Authorization": "Token " + TOKEN, "Content-Type": "application/json"}
|
||||
|
||||
data = {
|
||||
"app_ids": [
|
||||
"YOUR_APP_ID",
|
||||
],
|
||||
"data": {
|
||||
"title": "This is a filtered push",
|
||||
"content": "Only users with specified device_id(s) will see this notification.",
|
||||
},
|
||||
"filters": {"device_id": ["DEIVCE_ID_1", "DEVICE_ID_2"]}
|
||||
# additional keywords -> https://docs.pushe.co/docs/web-api/notification-keys
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
"https://api.pushe.co/v2/messaging/notifications/web/",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
print("status code => ", response.status_code)
|
||||
print("response => ", response.json())
|
||||
print("==========")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Success!")
|
||||
|
||||
data = response.json()
|
||||
|
||||
# hashed_id only generated for Non-Free plan
|
||||
if data["hashed_id"]:
|
||||
report_url = "https://pushe.co/report?id=%s" % data["hashed_id"]
|
||||
else:
|
||||
report_url = "no report url for your plan"
|
||||
|
||||
notif_id = data["wrapper_id"]
|
||||
print("report_url: %s" % report_url)
|
||||
print("notification id: %s" % notif_id)
|
||||
else:
|
||||
print("failed")
|
||||
|
||||
pass
|
||||
57
notification/pushe/send_transactional_notification.py
Normal file
57
notification/pushe/send_transactional_notification.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=4 sw=4 et
|
||||
|
||||
import requests
|
||||
from notification.pushe.constants import TOKEN
|
||||
|
||||
|
||||
def send_transactional_notification(data):
|
||||
# set header
|
||||
headers = {"Authorization": "Token " + TOKEN, "Content-Type": "application/json"}
|
||||
|
||||
# Webpush doc -> http://docs.pushe.co/docs/web-api/transactional-notification/
|
||||
|
||||
data = {
|
||||
"app_ids": [
|
||||
"YOUR_APP_ID",
|
||||
],
|
||||
"data": {
|
||||
"title": "Title",
|
||||
"content": "Content",
|
||||
},
|
||||
"custom_content": {"key1": "value1", "key2": "value2"},
|
||||
"device_id": [
|
||||
"device_id_1",
|
||||
"device_id_2",
|
||||
],
|
||||
}
|
||||
|
||||
# send request
|
||||
response = requests.post(
|
||||
"https://api.pushe.co/v2/messaging/web-rapid/",
|
||||
json=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
# get status_code and response
|
||||
print("status code => ", response.status_code)
|
||||
print("response => ", response.json())
|
||||
print("==========")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Success!")
|
||||
|
||||
data = response.json()
|
||||
|
||||
# hashed_id just generated for Non-Free plan
|
||||
if data["hashed_id"]:
|
||||
report_url = "https://pushe.co/report?id=%s" % data["hashed_id"]
|
||||
else:
|
||||
report_url = "no report url for your plan"
|
||||
|
||||
notif_id = data["wrapper_id"]
|
||||
print("report_url: %s" % report_url)
|
||||
print("notification id: %s" % notif_id)
|
||||
else:
|
||||
print("failed")
|
||||
pass
|
||||
Reference in New Issue
Block a user