-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Whapi notification provider (#4323)
Co-authored-by: Frank Elsinga <[email protected]>
- Loading branch information
1 parent
937c8a9
commit 822ce53
Showing
6 changed files
with
82 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,39 @@ | ||
const NotificationProvider = require("./notification-provider"); | ||
const axios = require("axios"); | ||
|
||
class Whapi extends NotificationProvider { | ||
name = "whapi"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||
const okMsg = "Sent Successfully."; | ||
|
||
try { | ||
const config = { | ||
headers: { | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + notification.whapiAuthToken, | ||
} | ||
}; | ||
|
||
let data = { | ||
"to": notification.whapiRecipient, | ||
"body": msg, | ||
}; | ||
|
||
let url = (notification.whapiApiUrl || "https://gate.whapi.cloud/").replace(/\/+$/, "") + "/messages/text"; | ||
|
||
await axios.post(url, data, config); | ||
|
||
return okMsg; | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = Whapi; |
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,33 @@ | ||
<template> | ||
<div class="mb-3"> | ||
<label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label> | ||
<input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control"> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label> | ||
<HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput> | ||
<i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text"> | ||
<a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a> | ||
</i18n-t> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label> | ||
<input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required> | ||
<div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "[email protected]", "[email protected]"]) }}</div> | ||
</div> | ||
|
||
<i18n-t tag="div" keypath="More info on:" class="mb-3 form-text"> | ||
<a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a> | ||
</i18n-t> | ||
</template> | ||
<script> | ||
import HiddenInput from "../HiddenInput.vue"; | ||
export default { | ||
components: { | ||
HiddenInput, | ||
} | ||
}; | ||
</script> |
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