From 6bf57766feb8321f860baf300140563cd9539053 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 14 Dec 2025 20:36:24 -0800 Subject: Init --- src/integrations/ntfy.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/integrations/ntfy.ts (limited to 'src/integrations/ntfy.ts') diff --git a/src/integrations/ntfy.ts b/src/integrations/ntfy.ts new file mode 100644 index 0000000..cf815ed --- /dev/null +++ b/src/integrations/ntfy.ts @@ -0,0 +1,40 @@ +import { Either, type IEither } from '@emprespresso/pengueno'; +import type { NtfyConfig, StoredRequest } from '../types/index.js'; + +export interface NtfyNotification { + topic: string; + title: string; + message: string; + tags?: string[]; + priority?: number; +} + +export async function sendNtfyNotification(config: NtfyConfig, request: StoredRequest): Promise> { + if (!config.enabled || !config.server || !config.topic) { + return Either.right(undefined); + } + + try { + const url = `${config.server}/${config.topic}`; + const title = `Webhook received: ${request.routeName}`; + const message = `Method: ${request.method}\nTimestamp: ${new Date(request.timestamp).toISOString()}\nUUID: ${request.uuid}`; + + const response = await fetch(url, { + method: 'POST', + headers: { + Title: title, + Tags: 'webhook,posthook', + Priority: '3', + }, + body: message, + }); + + if (!response.ok) { + return Either.left(new Error(`ntfy notification failed: ${response.statusText}`)); + } + + return Either.right(undefined); + } catch (err) { + return Either.left(err instanceof Error ? err : new Error(String(err))); + } +} -- cgit v1.2.3-70-g09d2