From 92e982a91004e8f519e21ee6a0e4d4d21ecae99c Mon Sep 17 00:00:00 2001 From: Hasan Basri Date: Thu, 8 Aug 2024 07:48:37 +0700 Subject: [PATCH] Add OneSender Webhook notification (#4971) Co-authored-by: Frank Elsinga --- server/notification-providers/onesender.js | 47 +++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/Onesender.vue | 81 ++++++++++++++++++++++ src/components/notifications/index.js | 2 + src/lang/en.json | 10 ++- 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/onesender.js create mode 100644 src/components/notifications/Onesender.vue diff --git a/server/notification-providers/onesender.js b/server/notification-providers/onesender.js new file mode 100644 index 000000000..4a33931a2 --- /dev/null +++ b/server/notification-providers/onesender.js @@ -0,0 +1,47 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Onesender extends NotificationProvider { + name = "Onesender"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let data = { + heartbeat: heartbeatJSON, + monitor: monitorJSON, + msg, + to: notification.onesenderReceiver, + type: "text", + recipient_type: "individual", + text: { + body: msg + } + }; + if (notification.onesenderTypeReceiver === "private") { + data.to = notification.onesenderReceiver + "@s.whatsapp.net"; + } else { + data.recipient_type = "group"; + data.to = notification.onesenderReceiver + "@g.us"; + } + let config = { + headers: { + "Authorization": "Bearer " + notification.onesenderToken, + } + }; + await axios.post(notification.onesenderURL, data, config); + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + + } + +} + +module.exports = Onesender; diff --git a/server/notification.js b/server/notification.js index 28b0db758..e6a2e6d5e 100644 --- a/server/notification.js +++ b/server/notification.js @@ -64,6 +64,7 @@ const SevenIO = require("./notification-providers/sevenio"); const Whapi = require("./notification-providers/whapi"); const GtxMessaging = require("./notification-providers/gtx-messaging"); const Cellsynt = require("./notification-providers/cellsynt"); +const Onesender = require("./notification-providers/onesender"); class Notification { @@ -111,6 +112,7 @@ class Notification { new Ntfy(), new Octopush(), new OneBot(), + new Onesender(), new Opsgenie(), new PagerDuty(), new FlashDuty(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 427366619..288b00559 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -135,6 +135,7 @@ export default { "ntfy": "Ntfy", "octopush": "Octopush", "OneBot": "OneBot", + "Onesender": "Onesender", "Opsgenie": "Opsgenie", "PagerDuty": "PagerDuty", "PagerTree": "PagerTree", diff --git a/src/components/notifications/Onesender.vue b/src/components/notifications/Onesender.vue new file mode 100644 index 000000000..81dbe7f0a --- /dev/null +++ b/src/components/notifications/Onesender.vue @@ -0,0 +1,81 @@ + + + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 5d49b8a4a..51642d7da 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -29,6 +29,7 @@ import Nostr from "./Nostr.vue"; import Ntfy from "./Ntfy.vue"; import Octopush from "./Octopush.vue"; import OneBot from "./OneBot.vue"; +import Onesender from "./Onesender.vue"; import Opsgenie from "./Opsgenie.vue"; import PagerDuty from "./PagerDuty.vue"; import FlashDuty from "./FlashDuty.vue"; @@ -98,6 +99,7 @@ const NotificationFormList = { "ntfy": Ntfy, "octopush": Octopush, "OneBot": OneBot, + "Onesender": Onesender, "Opsgenie": Opsgenie, "PagerDuty": PagerDuty, "FlashDuty": FlashDuty, diff --git a/src/lang/en.json b/src/lang/en.json index 7cb663b69..1382707d5 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -962,5 +962,13 @@ "threemaSenderIdentityFormat": "8 characters, usually starts with *", "threemaApiAuthenticationSecret": "Gateway-ID Secret", "threemaBasicModeInfo": "Note: This integration uses Threema Gateway in basic mode (server-based encryption). Further details can be found {0}.", - "apiKeysDisabledMsg": "API keys are disabled because authentication is disabled." + "apiKeysDisabledMsg": "API keys are disabled because authentication is disabled.", + "Host Onesender": "Host Onesender", + "Token Onesender": "Token Onesender", + "Recipient Type": "Recipient Type", + "Private Number": "Private Number", + "privateOnesenderDesc": "Make sure the number phone is valid. To send message into private number phone, ex: 628123456789", + "groupOnesenderDesc": "Make sure the GroupID is valid. To send message into Group, ex: 628123456789-342345", + "Group ID": "Group ID", + "wayToGetOnesenderUrlandToken":"You can get the URL and Token by going to the Onesender website. More info {0}" }