feat: Add VKTeams bot notification provider (#7365)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
class VKTeams extends NotificationProvider {
|
||||
name = "VKTeams";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
const baseUrl = (notification.vkteamsBaseUrl || "https://myteam.mail.ru").replace(/\/$/, "");
|
||||
|
||||
try {
|
||||
const rawParams = {
|
||||
token: notification.vkteamsBotToken,
|
||||
chatId: notification.vkteamsChatId,
|
||||
text: msg,
|
||||
};
|
||||
|
||||
if (notification.vkteamsUseTemplate && notification.vkteamsTemplate) {
|
||||
rawParams.text = await this.renderTemplate(
|
||||
notification.vkteamsTemplate,
|
||||
msg,
|
||||
monitorJSON,
|
||||
heartbeatJSON
|
||||
);
|
||||
|
||||
if (notification.vkteamsTemplateFormat && notification.vkteamsTemplateFormat !== "plain") {
|
||||
rawParams.parseMode = notification.vkteamsTemplateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(rawParams).toString();
|
||||
const config = this.getAxiosConfigWithProxy({});
|
||||
const response = await axios.get(`${baseUrl}/bot/v1/messages/sendText?${params}`, config);
|
||||
if (response.data?.ok === false) {
|
||||
throw new Error(`VKTeams API returned error: ${response.data.description}`);
|
||||
}
|
||||
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VKTeams;
|
||||
@@ -93,6 +93,7 @@ const Webpush = require("./notification-providers/Webpush");
|
||||
const HaloPSA = require("./notification-providers/HaloPSA");
|
||||
const Max = require("./notification-providers/max");
|
||||
const VK = require("./notification-providers/vk");
|
||||
const VKTeams = require("./notification-providers/vkteams");
|
||||
|
||||
class Notification {
|
||||
providerList = {};
|
||||
@@ -201,6 +202,7 @@ class Notification {
|
||||
new HaloPSA(),
|
||||
new Max(),
|
||||
new VK(),
|
||||
new VKTeams(),
|
||||
];
|
||||
for (let item of list) {
|
||||
if (!item.name) {
|
||||
|
||||
Reference in New Issue
Block a user