first push
This commit is contained in:
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