Skip to content

Commit

Permalink
Add OneSender Webhook notification (louislam#4971)
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Elsinga <[email protected]>
  • Loading branch information
hasanbasri1993 and CommanderStorm authored Aug 8, 2024
1 parent 13f6746 commit 92e982a
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 1 deletion.
47 changes: 47 additions & 0 deletions server/notification-providers/onesender.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -111,6 +112,7 @@ class Notification {
new Ntfy(),
new Octopush(),
new OneBot(),
new Onesender(),
new Opsgenie(),
new PagerDuty(),
new FlashDuty(),
Expand Down
1 change: 1 addition & 0 deletions src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default {
"ntfy": "Ntfy",
"octopush": "Octopush",
"OneBot": "OneBot",
"Onesender": "Onesender",
"Opsgenie": "Opsgenie",
"PagerDuty": "PagerDuty",
"PagerTree": "PagerTree",
Expand Down
81 changes: 81 additions & 0 deletions src/components/notifications/Onesender.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template>
<div class="mb-3">
<label for="host-onesender" class="form-label">{{ $t("Host Onesender") }}</label>
<input
id="host-onesender"
v-model="$parent.notification.onesenderURL"
type="url"
placeholder="https://xxxxxxxxxxx.com/api/v1/messages"
pattern="https?://.+"
class="form-control"
required
/>
</div>

<div class="mb-3">
<label for="receiver-onesender" class="form-label">{{ $t("Token Onesender") }}</label>
<HiddenInput id="receiver-onesender" v-model="$parent.notification.onesenderToken" :required="true" autocomplete="false"></HiddenInput>
<i18n-t tag="div" keypath="wayToGetOnesenderUrlandToken" class="form-text">
<a href="https://onesender.net/" target="_blank">{{ $t("here") }}</a>
</i18n-t>
</div>

<div class="mb-3">
<label for="webhook-request-body" class="form-label">{{ $t("Recipient Type") }}</label>
<select
id="webhook-request-body"
v-model="$parent.notification.onesenderTypeReceiver"
class="form-select"
required
>
<option value="private">{{ $t("Private Number") }}</option>
<option value="group">{{ $t("Group ID") }}</option>
</select>
</div>
<div v-if="$parent.notification.onesenderTypeReceiver == 'private'" class="form-text">{{ $t("privateOnesenderDesc", ['"application/json"']) }}</div>
<div v-else class="form-text">{{ $t("groupOnesenderDesc") }}</div>
<div class="mb-3">
<input
id="type-receiver-onesender"
v-model="$parent.notification.onesenderReceiver"
type="text"
placeholder="628123456789 or 628123456789-34534"
class="form-control"
required
/>
</div>
<div class="mb-3">
<input
id="type-receiver-onesender"
v-model="computedReceiverResult"
type="text"
class="form-control"
disabled
/>
</div>
</template>

<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
data() {
return {};
},
computed: {
computedReceiverResult() {
let receiver = this.$parent.notification.onesenderReceiver;
return this.$parent.notification.onesenderTypeReceiver === "private" ? receiver + "@s.whatsapp.net" : receiver + "@g.us";
},
},
};
</script>

<style lang="scss" scoped>
textarea {
min-height: 200px;
}
</style>
2 changes: 2 additions & 0 deletions src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -98,6 +99,7 @@ const NotificationFormList = {
"ntfy": Ntfy,
"octopush": Octopush,
"OneBot": OneBot,
"Onesender": Onesender,
"Opsgenie": Opsgenie,
"PagerDuty": PagerDuty,
"FlashDuty": FlashDuty,
Expand Down
10 changes: 9 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

0 comments on commit 92e982a

Please sign in to comment.