feat: Add VK notification provider (#7182)
parent
cdfca84664
commit
4a6161c579
@ -0,0 +1,44 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
class VK extends NotificationProvider {
|
||||
name = "VK";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
const url = "https://api.vk.ru/method/messages.send";
|
||||
|
||||
try {
|
||||
const data = new URLSearchParams({
|
||||
access_token: notification.vkAccessToken,
|
||||
v: notification.vkApiVersion,
|
||||
peer_id: notification.vkPeerId,
|
||||
message: msg,
|
||||
dont_parse_links: notification.vkDontParseLinks ? "1" : "0",
|
||||
random_id: String(Math.floor(Math.random() * 2147483647)),
|
||||
});
|
||||
|
||||
const config = this.getAxiosConfigWithProxy({});
|
||||
const response = await axios.post(url, data, config);
|
||||
|
||||
if (response.data?.error) {
|
||||
throw new Error(
|
||||
`VK API returned error ${response.data.error.error_code}: ${response.data.error.error_msg}`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof response.data?.response === "undefined") {
|
||||
throw new Error("Invalid VK API response");
|
||||
}
|
||||
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VK;
|
||||
@ -0,0 +1,57 @@
|
||||
<template>
|
||||
<div class="mb-3">
|
||||
<label for="vk-access-token" class="form-label">{{ $t("Access Token") }}</label>
|
||||
<HiddenInput
|
||||
id="vk-access-token"
|
||||
v-model="$parent.notification.vkAccessToken"
|
||||
:required="true"
|
||||
autocomplete="new-password"
|
||||
></HiddenInput>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="vk-api-version" class="form-label">{{ $t("API Version") }}</label>
|
||||
<input
|
||||
id="vk-api-version"
|
||||
v-model="$parent.notification.vkApiVersion"
|
||||
type="text"
|
||||
class="form-control"
|
||||
required
|
||||
/>
|
||||
<div class="form-text">
|
||||
{{ $t("vkApiVersionDescription") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="vk-peer-id" class="form-label">{{ $t("Peer ID") }}</label>
|
||||
<input id="vk-peer-id" v-model="$parent.notification.vkPeerId" type="text" class="form-control" required />
|
||||
<div class="form-text">
|
||||
{{ $t("vkPeerIdDescription") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input v-model="$parent.notification.vkDontParseLinks" class="form-check-input" type="checkbox" />
|
||||
<label class="form-check-label">{{ $t("vkDontParseLinks") }}</label>
|
||||
</div>
|
||||
<div class="form-text">
|
||||
{{ $t("vkDontParseLinksDescription") }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HiddenInput from "../HiddenInput.vue";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
HiddenInput,
|
||||
},
|
||||
mounted() {
|
||||
this.$parent.notification.vkApiVersion ||= "5.199";
|
||||
this.$parent.notification.vkDontParseLinks ||= false;
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Loading…
Reference in new issue