discord
This commit is contained in:
1 parent
afc27c804d
commit
d665e95f02
2 files changed
+23
-12
No files matched your search
@@ -1,14 +1,15 @@
|
|||||||
const SERVICE_NAME = "DiscordProvider";
|
const SERVICE_NAME = "DiscordProvider";
|
||||||
import type { Notification } from "@/types/index.js";
|
import type { AlertDiscordPayload, DiscordEmbedField, Notification } from "@/types/index.js";
|
||||||
import { INotificationProvider } from "@/service/index.js";
|
import { INotificationProvider } from "@/service/index.js";
|
||||||
import { getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js";
|
import { getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js";
|
||||||
import type { NotificationMessage } from "@/types/notificationMessage.js";
|
import type { NotificationMessage, NotificationSeverity } from "@/types/notificationMessage.js";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
export class DiscordProvider implements INotificationProvider {
|
export class DiscordProvider implements INotificationProvider {
|
||||||
private logger: any;
|
private logger: ILogger;
|
||||||
|
|
||||||
constructor(logger: any) {
|
constructor(logger: ILogger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,9 +37,6 @@ export class DiscordProvider implements INotificationProvider {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* New unified message format implementation
|
|
||||||
*/
|
|
||||||
async sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean> {
|
async sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean> {
|
||||||
if (!notification.address) {
|
if (!notification.address) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
@@ -71,18 +69,17 @@ export class DiscordProvider implements INotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildDiscordEmbed(message: NotificationMessage): any {
|
private buildDiscordEmbed(message: NotificationMessage): AlertDiscordPayload {
|
||||||
// Map severity to Discord embed colors
|
const colorMap: Record<NotificationSeverity, number> = {
|
||||||
const colorMap: Record<string, number> = {
|
|
||||||
critical: 0xdc2626, // red-600
|
critical: 0xdc2626, // red-600
|
||||||
warning: 0xf59e0b, // amber-500
|
warning: 0xf59e0b, // amber-500
|
||||||
info: 0x3b82f6, // blue-500
|
info: 0x3b82f6, // blue-500
|
||||||
success: 0x10b981, // green-500
|
success: 0x10b981, // green-500
|
||||||
};
|
};
|
||||||
|
|
||||||
const color = colorMap[message.severity] || colorMap.info;
|
const color = colorMap[message.severity] ?? colorMap.info;
|
||||||
|
|
||||||
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
const fields: Array<DiscordEmbedField> = [];
|
||||||
|
|
||||||
// Add monitor details
|
// Add monitor details
|
||||||
fields.push({
|
fields.push({
|
||||||
|
|||||||
@@ -15,6 +15,20 @@ export interface AlertMatrixPayload {
|
|||||||
htmlText: string;
|
htmlText: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DiscordEmbedField {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
inline?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AlertDiscordPayload {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
color: number;
|
||||||
|
fields: DiscordEmbedField[];
|
||||||
|
timestamp: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Alert {
|
export interface Alert {
|
||||||
channel: NotificationChannel;
|
channel: NotificationChannel;
|
||||||
address?: string;
|
address?: string;
|
||||||
|
|||||||
Reference in new issue
Block a user