From ea43422ccfae82f74dc2a0b1b00895a78d4df6ec Mon Sep 17 00:00:00 2001 From: Zack Elia Date: Sun, 9 Jan 2022 12:05:11 -0500 Subject: [PATCH] Implement gorush notifications --- server/notification-providers/gorush.js | 42 ++++++++++++++++++++ server/notification.js | 4 +- src/components/notifications/Gorush.vue | 51 +++++++++++++++++++++++++ src/components/notifications/index.js | 4 +- src/languages/en.js | 1 + 5 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 server/notification-providers/gorush.js create mode 100644 src/components/notifications/Gorush.vue diff --git a/server/notification-providers/gorush.js b/server/notification-providers/gorush.js new file mode 100644 index 000000000..58da5525e --- /dev/null +++ b/server/notification-providers/gorush.js @@ -0,0 +1,42 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Gorush extends NotificationProvider { + + name = "gorush"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + let platformMapping = { + "ios": 1, + "android": 2, + "huawei": 3, + }; + + try { + let data = { + "notifications": [ + { + "tokens": [notification.gorushDeviceToken], + "platform": platformMapping[notification.gorushPlatform], + "message": msg, + // Optional + "title": notification.gorushTitle, + "priority": notification.gorushPriority, + "retry": parseInt(notification.gorushRetry) || 0, + "topic": notification.gorushTopic, + } + ] + }; + let config = {}; + + await axios.post(`${notification.gorushServerURL}/api/push`, data, config); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Gorush; diff --git a/server/notification.js b/server/notification.js index 4d72c81c7..837828309 100644 --- a/server/notification.js +++ b/server/notification.js @@ -27,6 +27,7 @@ const SerwerSMS = require("./notification-providers/serwersms"); const Stackfield = require("./notification-providers/stackfield"); const WeCom = require("./notification-providers/wecom"); const GoogleChat = require("./notification-providers/google-chat"); +const Gorush = require("./notification-providers/gorush"); class Notification { @@ -65,7 +66,8 @@ class Notification { new SerwerSMS(), new Stackfield(), new WeCom(), - new GoogleChat() + new GoogleChat(), + new Gorush() ]; for (let item of list) { diff --git a/src/components/notifications/Gorush.vue b/src/components/notifications/Gorush.vue new file mode 100644 index 000000000..b53be2d26 --- /dev/null +++ b/src/components/notifications/Gorush.vue @@ -0,0 +1,51 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 03945f90e..7883890b4 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -26,6 +26,7 @@ import SerwerSMS from "./SerwerSMS.vue"; import Stackfield from './Stackfield.vue'; import WeCom from "./WeCom.vue"; import GoogleChat from "./GoogleChat.vue"; +import Gorush from "./Gorush.vue"; /** * Manage all notification form. @@ -60,7 +61,8 @@ const NotificationFormList = { "serwersms": SerwerSMS, "stackfield": Stackfield, "WeCom": WeCom, - "GoogleChat": GoogleChat + "GoogleChat": GoogleChat, + "gorush": Gorush }; export default NotificationFormList; diff --git a/src/languages/en.js b/src/languages/en.js index 47513466c..37e831e6d 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -361,4 +361,5 @@ export default { smtpDkimHashAlgo: "Hash Algorithm (Optional)", smtpDkimheaderFieldNames: "Header Keys to sign (Optional)", smtpDkimskipFields: "Header Keys not to sign (Optional)", + gorush: "Gorush", };