forked from louislam/uptime-kuma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OneSender Webhook notification (louislam#4971)
Co-authored-by: Frank Elsinga <[email protected]>
- Loading branch information
1 parent
13f6746
commit 92e982a
Showing
6 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters