Merge pull request #3439 from LeC-D/fix/telegram-notification-type
feat(notifications): add Telegram notification channel (#2753)
This commit is contained in:
12 files changed
+260
-22
No files matched your search
@@ -1,28 +1,76 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { notificationSchema } from "@/Validation/notifications";
|
import { notificationSchema } from "@/Validation/notifications";
|
||||||
|
import type { NotificationFormData } from "@/Validation/notifications";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
|
|
||||||
interface UseNotificationFormOptions {
|
interface UseNotificationFormOptions {
|
||||||
data?: Notification | null;
|
data?: Notification | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildDefaults(data: Notification | null): NotificationFormData {
|
||||||
|
if (data?.type === "matrix") {
|
||||||
|
return {
|
||||||
|
type: "matrix",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
homeserverUrl: data.homeserverUrl || "",
|
||||||
|
roomId: data.roomId || "",
|
||||||
|
accessToken: data.accessToken || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "telegram") {
|
||||||
|
return {
|
||||||
|
type: "telegram",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
accessToken: data.accessToken || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "slack") {
|
||||||
|
return {
|
||||||
|
type: "slack",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "discord") {
|
||||||
|
return {
|
||||||
|
type: "discord",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "webhook") {
|
||||||
|
return {
|
||||||
|
type: "webhook",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "pager_duty") {
|
||||||
|
return {
|
||||||
|
type: "pager_duty",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (data?.type === "teams") {
|
||||||
|
return {
|
||||||
|
type: "teams",
|
||||||
|
notificationName: data.notificationName || "",
|
||||||
|
address: data.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Default: email (covers both data === null and data.type === "email")
|
||||||
|
return {
|
||||||
|
type: "email",
|
||||||
|
notificationName: data?.notificationName || "",
|
||||||
|
address: data?.address || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
|
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const defaults =
|
const defaults = buildDefaults(data);
|
||||||
data?.type === "matrix"
|
|
||||||
? {
|
|
||||||
type: "matrix" as const,
|
|
||||||
notificationName: data.notificationName || "",
|
|
||||||
homeserverUrl: data.homeserverUrl || "",
|
|
||||||
roomId: data.roomId || "",
|
|
||||||
accessToken: data.accessToken || "",
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
type: (data?.type || "email") as Exclude<Notification["type"], "matrix">,
|
|
||||||
notificationName: data?.notificationName || "",
|
|
||||||
address: data?.address || "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return { schema: notificationSchema, defaults };
|
return { schema: notificationSchema, defaults };
|
||||||
}, [data]);
|
}, [data]);
|
||||||
};
|
};
|
||||||
@@ -147,7 +147,7 @@ const NotificationsCreatePage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{watchedType !== "matrix" && (
|
{watchedType !== "matrix" && watchedType !== "telegram" && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={addressConfig.title}
|
title={addressConfig.title}
|
||||||
subtitle={addressConfig.description}
|
subtitle={addressConfig.description}
|
||||||
@@ -155,7 +155,7 @@ const NotificationsCreatePage = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
name="address"
|
name="address"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={defaults.address}
|
defaultValue={"address" in defaults ? defaults.address : ""}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
@@ -171,6 +171,49 @@ const NotificationsCreatePage = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{watchedType === "telegram" && (
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.notifications.form.telegram.title")}
|
||||||
|
subtitle={t("pages.notifications.form.telegram.description")}
|
||||||
|
rightContent={
|
||||||
|
<Stack spacing={theme.spacing(8)}>
|
||||||
|
<Controller
|
||||||
|
name="accessToken"
|
||||||
|
control={control}
|
||||||
|
defaultValue={"accessToken" in defaults ? defaults.accessToken : ""}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="text"
|
||||||
|
fieldLabel={t("pages.notifications.form.telegram.optionBotToken")}
|
||||||
|
placeholder={t(
|
||||||
|
"pages.notifications.form.telegram.placeholderBotToken"
|
||||||
|
)}
|
||||||
|
fullWidth
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="address"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="text"
|
||||||
|
fieldLabel={t("pages.notifications.form.telegram.optionChatId")}
|
||||||
|
placeholder={t("pages.notifications.form.telegram.placeholderChatId")}
|
||||||
|
fullWidth
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{watchedType === "matrix" && (
|
{watchedType === "matrix" && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.notifications.form.matrix.title")}
|
title={t("pages.notifications.form.matrix.title")}
|
||||||
@@ -180,7 +223,7 @@ const NotificationsCreatePage = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
name="homeserverUrl"
|
name="homeserverUrl"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={defaults.homeserverUrl}
|
defaultValue={"homeserverUrl" in defaults ? defaults.homeserverUrl : ""}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
@@ -196,7 +239,7 @@ const NotificationsCreatePage = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
name="roomId"
|
name="roomId"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={defaults.roomId}
|
defaultValue={"roomId" in defaults ? defaults.roomId : ""}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
@@ -212,7 +255,7 @@ const NotificationsCreatePage = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
name="accessToken"
|
name="accessToken"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={defaults.accessToken}
|
defaultValue={"accessToken" in defaults ? defaults.accessToken : ""}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const NotificationChannels = [
|
|||||||
"pager_duty",
|
"pager_duty",
|
||||||
"matrix",
|
"matrix",
|
||||||
"teams",
|
"teams",
|
||||||
|
"telegram",
|
||||||
] as const;
|
] as const;
|
||||||
export type NotificationChannel = (typeof NotificationChannels)[number];
|
export type NotificationChannel = (typeof NotificationChannels)[number];
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ const teamsSchema = baseSchema.extend({
|
|||||||
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const telegramSchema = baseSchema.extend({
|
||||||
|
type: z.literal("telegram"),
|
||||||
|
address: z.string().min(1, "Chat ID is required"),
|
||||||
|
accessToken: z.string().min(1, "Bot token is required"),
|
||||||
|
});
|
||||||
|
|
||||||
export const notificationSchema = z.discriminatedUnion("type", [
|
export const notificationSchema = z.discriminatedUnion("type", [
|
||||||
emailSchema,
|
emailSchema,
|
||||||
slackSchema,
|
slackSchema,
|
||||||
@@ -58,6 +64,7 @@ export const notificationSchema = z.discriminatedUnion("type", [
|
|||||||
pagerDutySchema,
|
pagerDutySchema,
|
||||||
matrixSchema,
|
matrixSchema,
|
||||||
teamsSchema,
|
teamsSchema,
|
||||||
|
telegramSchema,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export type NotificationFormData = z.infer<typeof notificationSchema>;
|
export type NotificationFormData = z.infer<typeof notificationSchema>;
|
||||||
@@ -951,6 +951,14 @@
|
|||||||
"description": "Select the type of notification channel to create.",
|
"description": "Select the type of notification channel to create.",
|
||||||
"optionType": "Type",
|
"optionType": "Type",
|
||||||
"title": "Channel type"
|
"title": "Channel type"
|
||||||
|
},
|
||||||
|
"telegram": {
|
||||||
|
"title": "Telegram configuration",
|
||||||
|
"description": "Configure your Telegram bot to send notifications.",
|
||||||
|
"optionBotToken": "Bot token",
|
||||||
|
"placeholderBotToken": "123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ",
|
||||||
|
"optionChatId": "Chat ID",
|
||||||
|
"placeholderChatId": "-1001234567890"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"table": {
|
"table": {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
PagerDutyProvider,
|
PagerDutyProvider,
|
||||||
MatrixProvider,
|
MatrixProvider,
|
||||||
TeamsProvider,
|
TeamsProvider,
|
||||||
|
TelegramProvider,
|
||||||
// Interfaces
|
// Interfaces
|
||||||
INetworkService,
|
INetworkService,
|
||||||
IEmailService,
|
IEmailService,
|
||||||
@@ -296,6 +297,7 @@ export const initializeServices = async ({
|
|||||||
const pagerDutyProvider = new PagerDutyProvider(logger);
|
const pagerDutyProvider = new PagerDutyProvider(logger);
|
||||||
const matrixProvider = new MatrixProvider(logger);
|
const matrixProvider = new MatrixProvider(logger);
|
||||||
const teamsProvider = new TeamsProvider(logger);
|
const teamsProvider = new TeamsProvider(logger);
|
||||||
|
const telegramProvider = new TelegramProvider(logger);
|
||||||
|
|
||||||
const notificationsService = new NotificationsService(
|
const notificationsService = new NotificationsService(
|
||||||
notificationsRepository,
|
notificationsRepository,
|
||||||
@@ -307,6 +309,7 @@ export const initializeServices = async ({
|
|||||||
pagerDutyProvider,
|
pagerDutyProvider,
|
||||||
matrixProvider,
|
matrixProvider,
|
||||||
teamsProvider,
|
teamsProvider,
|
||||||
|
telegramProvider,
|
||||||
settingsService,
|
settingsService,
|
||||||
logger,
|
logger,
|
||||||
notificationMessageBuilder
|
notificationMessageBuilder
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const NotificationSchema = new Schema<NotificationDocument>(
|
|||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ["email", "slack", "discord", "webhook", "pager_duty", "matrix", "teams"] as NotificationChannel[],
|
enum: ["email", "slack", "discord", "webhook", "pager_duty", "matrix", "teams", "telegram"] as NotificationChannel[],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
notificationName: {
|
notificationName: {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export * from "@/service/infrastructure/notificationProviders/pagerduty.js";
|
|||||||
export * from "@/service/infrastructure/notificationProviders/slack.js";
|
export * from "@/service/infrastructure/notificationProviders/slack.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/teams.js";
|
export * from "@/service/infrastructure/notificationProviders/teams.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
||||||
|
export * from "@/service/infrastructure/notificationProviders/telegram.js";
|
||||||
|
|
||||||
// System services
|
// System services
|
||||||
export * from "@/service/system/settingsService.js";
|
export * from "@/service/system/settingsService.js";
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
const SERVICE_NAME = "TelegramProvider";
|
||||||
|
import type { Notification } from "@/types/index.js";
|
||||||
|
import { INotificationProvider } from "@/service/index.js";
|
||||||
|
import type { NotificationMessage } from "@/types/notificationMessage.js";
|
||||||
|
import { getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js";
|
||||||
|
import got from "got";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
|
export class TelegramProvider implements INotificationProvider {
|
||||||
|
private logger: ILogger;
|
||||||
|
|
||||||
|
constructor(logger: ILogger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
|
||||||
|
if (!notification.address || !notification.accessToken) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await got.post(`https://api.telegram.org/bot${notification.accessToken}/sendMessage`, {
|
||||||
|
json: {
|
||||||
|
chat_id: notification.address,
|
||||||
|
text: getTestMessage(),
|
||||||
|
parse_mode: "HTML",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
const errMsg = error instanceof Error ? error.message : "unknown error";
|
||||||
|
const errStack = error instanceof Error ? error.stack : undefined;
|
||||||
|
this.logger.warn({
|
||||||
|
message: "Telegram test alert failed",
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "sendTestAlert",
|
||||||
|
stack: errStack,
|
||||||
|
details: { error: errMsg },
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean> {
|
||||||
|
if (!notification.address || !notification.accessToken) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = this.buildTelegramText(message);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await got.post(`https://api.telegram.org/bot${notification.accessToken}/sendMessage`, {
|
||||||
|
json: {
|
||||||
|
chat_id: notification.address,
|
||||||
|
text,
|
||||||
|
parse_mode: "HTML",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.logger.info({
|
||||||
|
message: "Telegram notification sent",
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "sendMessage",
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
const errMsg = error instanceof Error ? error.message : "unknown error";
|
||||||
|
const errStack = error instanceof Error ? error.stack : undefined;
|
||||||
|
this.logger.warn({
|
||||||
|
message: "Telegram alert failed",
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "sendMessage",
|
||||||
|
stack: errStack,
|
||||||
|
details: { error: errMsg },
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildTelegramText(message: NotificationMessage): string {
|
||||||
|
const lines: string[] = [];
|
||||||
|
|
||||||
|
lines.push(`<b>${message.content.title}</b>`);
|
||||||
|
lines.push(message.content.summary);
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
lines.push("<b>Monitor Details:</b>");
|
||||||
|
lines.push(`• Name: ${message.monitor.name}`);
|
||||||
|
lines.push(`• URL: ${message.monitor.url}`);
|
||||||
|
lines.push(`• Type: ${message.monitor.type}`);
|
||||||
|
lines.push(`• Status: ${message.monitor.status}`);
|
||||||
|
|
||||||
|
if (message.content.details && message.content.details.length > 0) {
|
||||||
|
lines.push("");
|
||||||
|
lines.push("<b>Additional Information:</b>");
|
||||||
|
message.content.details.forEach((detail) => lines.push(`• ${detail}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.content.thresholds && message.content.thresholds.length > 0) {
|
||||||
|
lines.push("");
|
||||||
|
lines.push("<b>Threshold Breaches:</b>");
|
||||||
|
message.content.thresholds.forEach((breach) => {
|
||||||
|
lines.push(`• ${breach.metric.toUpperCase()}: ${breach.formattedValue} (threshold: ${breach.threshold}${breach.unit})`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.content.incident) {
|
||||||
|
lines.push("");
|
||||||
|
lines.push(`<a href="${message.clientHost}/incidents/${message.monitor.id}">View Incident</a>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ export class NotificationsService implements INotificationsService {
|
|||||||
private pagerDutyProvider: INotificationProvider;
|
private pagerDutyProvider: INotificationProvider;
|
||||||
private matrixProvider: INotificationProvider;
|
private matrixProvider: INotificationProvider;
|
||||||
private teamsProvider: INotificationProvider;
|
private teamsProvider: INotificationProvider;
|
||||||
|
private telegramProvider: INotificationProvider;
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
private settingsService: ISettingsService;
|
private settingsService: ISettingsService;
|
||||||
private notificationMessageBuilder: INotificationMessageBuilder;
|
private notificationMessageBuilder: INotificationMessageBuilder;
|
||||||
@@ -47,6 +48,7 @@ export class NotificationsService implements INotificationsService {
|
|||||||
pagerDutyProvider: INotificationProvider,
|
pagerDutyProvider: INotificationProvider,
|
||||||
matrixProvider: INotificationProvider,
|
matrixProvider: INotificationProvider,
|
||||||
teamsProvider: INotificationProvider,
|
teamsProvider: INotificationProvider,
|
||||||
|
telegramProvider: INotificationProvider,
|
||||||
settingsService: ISettingsService,
|
settingsService: ISettingsService,
|
||||||
logger: ILogger,
|
logger: ILogger,
|
||||||
notificationMessageBuilder: INotificationMessageBuilder
|
notificationMessageBuilder: INotificationMessageBuilder
|
||||||
@@ -60,6 +62,7 @@ export class NotificationsService implements INotificationsService {
|
|||||||
this.pagerDutyProvider = pagerDutyProvider;
|
this.pagerDutyProvider = pagerDutyProvider;
|
||||||
this.matrixProvider = matrixProvider;
|
this.matrixProvider = matrixProvider;
|
||||||
this.teamsProvider = teamsProvider;
|
this.teamsProvider = teamsProvider;
|
||||||
|
this.telegramProvider = telegramProvider;
|
||||||
this.settingsService = settingsService;
|
this.settingsService = settingsService;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.notificationMessageBuilder = notificationMessageBuilder;
|
this.notificationMessageBuilder = notificationMessageBuilder;
|
||||||
@@ -97,6 +100,8 @@ export class NotificationsService implements INotificationsService {
|
|||||||
return await this.emailProvider.sendMessage!(notification, notificationMessage);
|
return await this.emailProvider.sendMessage!(notification, notificationMessage);
|
||||||
case "teams":
|
case "teams":
|
||||||
return await this.teamsProvider.sendMessage!(notification, notificationMessage);
|
return await this.teamsProvider.sendMessage!(notification, notificationMessage);
|
||||||
|
case "telegram":
|
||||||
|
return await this.telegramProvider.sendMessage!(notification, notificationMessage);
|
||||||
default:
|
default:
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Unknown notification type: ${notification.type}`,
|
message: `Unknown notification type: ${notification.type}`,
|
||||||
@@ -157,6 +162,8 @@ export class NotificationsService implements INotificationsService {
|
|||||||
return await this.webhookProvider.sendTestAlert(notification);
|
return await this.webhookProvider.sendTestAlert(notification);
|
||||||
case "teams":
|
case "teams":
|
||||||
return await this.teamsProvider.sendTestAlert(notification);
|
return await this.teamsProvider.sendTestAlert(notification);
|
||||||
|
case "telegram":
|
||||||
|
return await this.telegramProvider.sendTestAlert(notification);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const NotificationChannels = ["email", "slack", "discord", "webhook", "pager_duty", "matrix", "teams"] as const;
|
export const NotificationChannels = ["email", "slack", "discord", "webhook", "pager_duty", "matrix", "teams", "telegram"] as const;
|
||||||
export type NotificationChannel = (typeof NotificationChannels)[number];
|
export type NotificationChannel = (typeof NotificationChannels)[number];
|
||||||
|
|
||||||
export interface Notification {
|
export interface Notification {
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ export const createNotificationBodyValidation = z.discriminatedUnion("type", [
|
|||||||
type: z.literal("teams"),
|
type: z.literal("teams"),
|
||||||
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
address: z.url({ message: "Please enter a valid Webhook URL" }),
|
||||||
}),
|
}),
|
||||||
|
// Telegram notification
|
||||||
|
z.object({
|
||||||
|
notificationName: z.string().min(1, "Notification name is required"),
|
||||||
|
type: z.literal("telegram"),
|
||||||
|
address: z.string().min(1, "Chat ID is required"),
|
||||||
|
accessToken: z.string().min(1, "Bot token is required"),
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const testNotificationBodyValidation = createNotificationBodyValidation;
|
export const testNotificationBodyValidation = createNotificationBodyValidation;
|
||||||
|
|||||||
Reference in new issue
Block a user