diff --git a/server/src/service/infrastructure/notificationProviders/INotificationProvider.ts b/server/src/service/infrastructure/notificationProviders/INotificationProvider.ts index 2743dfab9..b5c886408 100644 --- a/server/src/service/infrastructure/notificationProviders/INotificationProvider.ts +++ b/server/src/service/infrastructure/notificationProviders/INotificationProvider.ts @@ -1,7 +1,30 @@ import type { Notification } from "@/types/index.js"; import type { NotificationMessage } from "@/types/notificationMessage.js"; +import { ILogger } from "@/utils/logger.js"; +import type { OptionsOfJSONResponseBody } from "got"; +export const DEFAULT_NOTIFICATION_TIMEOUT_MS = 30_000; export interface INotificationProvider { sendMessage: (notification: Notification, message: NotificationMessage) => Promise; sendTestAlert(notification: Partial): Promise; } + +export abstract class NotificationProvider implements INotificationProvider { + protected readonly logger: ILogger; + protected readonly timeoutMs: number; + + constructor(logger: ILogger, timeoutMs: number = DEFAULT_NOTIFICATION_TIMEOUT_MS) { + this.logger = logger; + this.timeoutMs = timeoutMs; + } + + protected gotRequestOptions(): Pick { + return { + timeout: { request: this.timeoutMs }, + retry: { limit: 0 }, + }; + } + + abstract sendMessage(notification: Notification, message: NotificationMessage): Promise; + abstract sendTestAlert(notification: Partial): Promise; +}