You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
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;
|