2
0
mirror of https://github.com/frappe/frappe.git synced 2024-06-03 00:50:53 +00:00

chore: Add Push Notification Settings to Integrations workspace

This commit is contained in:
Rucha Mahabal 2024-02-28 11:07:22 +05:30
parent 3450c1ae1e
commit 8305affddd
3 changed files with 28 additions and 9 deletions

View File

@ -3,6 +3,7 @@
"allow_rename": 1,
"beta": 1,
"creation": "2024-01-04 11:36:08.013039",
"description": "Enabling this will register your site on a central relay server to send push notifications for all installed apps through Firebase Cloud Messaging. This server only stores user tokens and error logs, and no messages are saved.",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
@ -28,14 +29,12 @@
{
"fieldname": "api_key",
"fieldtype": "Data",
"label": "API Key",
"read_only": 1
"label": "API Key"
},
{
"fieldname": "api_secret",
"fieldtype": "Password",
"label": "API Secret",
"read_only": 1
"label": "API Secret"
},
{
"description": "Enabling this will register your site on a central relay server to send push notifications for all installed apps through Firebase Cloud Messaging. This server only stores user tokens and error logs, and no messages are saved. ",
@ -47,7 +46,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-02-28 00:37:18.398000",
"modified": "2024-02-28 11:03:30.518196",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Push Notification Settings",

View File

@ -1,6 +1,6 @@
{
"charts": [],
"content": "[{\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Reports &amp; Masters</b></span>\",\"col\":12}},{\"type\":\"card\",\"data\":{\"card_name\":\"Backup\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Google Services\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Authentication\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}}]",
"content": "[{\"id\":\"NPK_AfSLQ2\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Reports &amp; Masters</b></span>\",\"col\":12}},{\"id\":\"lDOo58F7ZI\",\"type\":\"card\",\"data\":{\"card_name\":\"Backup\",\"col\":4}},{\"id\":\"ij1pcK8jst\",\"type\":\"card\",\"data\":{\"card_name\":\"Google Services\",\"col\":4}},{\"id\":\"aTlMujEHpN\",\"type\":\"card\",\"data\":{\"card_name\":\"Authentication\",\"col\":4}},{\"id\":\"gY5NXKtXss\",\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}},{\"id\":\"n_CI3GGqW-\",\"type\":\"card\",\"data\":{\"card_name\":\"Push Notifications\",\"col\":4}}]",
"creation": "2020-03-02 15:16:18.714190",
"custom_blocks": [],
"docstatus": 0,
@ -197,9 +197,28 @@
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Push Notifications",
"link_count": 1,
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Push Notification Settings",
"link_count": 0,
"link_to": "Push Notification Settings",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
],
"modified": "2023-05-24 14:58:55.910408",
"modified": "2024-02-28 10:47:38.188832",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Integrations",

View File

@ -168,6 +168,7 @@ class PushNotification:
raise Exception("Body should be at max 1000 characters")
if strip_html:
body = frappe.utils.strip_html(body)
response_data = self._send_post_request(
"notification_relay.api.send_notification.topic",
{"topic_name": topic_name, "title": title, "body": body, "data": json.dumps(data)},
@ -282,12 +283,12 @@ def auth_webhook():
# Subscribe and Unsubscribe API
@frappe.whitelist(methods=["GET"])
def subscribe(fcm_token: str, project_name: str):
def subscribe(fcm_token: str, project_name: str) -> dict:
success, message = PushNotification(project_name).add_token(frappe.session.user, fcm_token)
return {"success": success, "message": message}
@frappe.whitelist(methods=["GET"])
def unsubscribe(fcm_token: str, project_name: str):
def unsubscribe(fcm_token: str, project_name: str) -> dict:
success, message = PushNotification(project_name).remove_token(frappe.session.user, fcm_token)
return {"success": success, "message": message}