Files
at-mintel/packages/observability/src/notifications/gotify.ts
Marc Mintel 61e78ea672
All checks were successful
Monorepo Pipeline / 🧪 Quality Assurance (push) Successful in 3m50s
Monorepo Pipeline / 🚀 Release (push) Successful in 3m38s
Monorepo Pipeline / 🐳 Build & Push Images (push) Successful in 7m6s
feat: integrate observability
2026-02-07 10:23:51 +01:00

57 lines
1.5 KiB
TypeScript

import { NotificationOptions, NotificationService } from "./service";
export interface GotifyConfig {
url: string;
token: string;
enabled: boolean;
}
/**
* Gotify Notification Service implementation.
*/
export class GotifyNotificationService implements NotificationService {
constructor(
private config: GotifyConfig,
private logger?: { error(msg: string, data?: any): void },
) {}
async notify(options: NotificationOptions): Promise<void> {
if (!this.config.enabled) return;
try {
const { title, message, priority = 4 } = options;
// Ensure we have a trailing slash for base URL, then append 'message'
const baseUrl = this.config.url.endsWith("/")
? this.config.url
: `${this.config.url}/`;
const url = new URL("message", baseUrl);
url.searchParams.set("token", this.config.token);
const response = await fetch(url.toString(), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
message,
priority,
}),
});
if (!response.ok) {
const errorText = await response.text();
this.logger?.error("Gotify notification failed", {
status: response.status,
error: errorText.slice(0, 100),
});
}
} catch (error) {
this.logger?.error("Gotify notification error", {
error: (error as Error).message,
});
}
}
}