diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 20:36:24 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 20:36:24 -0800 |
| commit | 6bf57766feb8321f860baf300140563cd9539053 (patch) | |
| tree | d80ff78c2a7f4dbea79f9ee850542aee1b735ef4 /src/integrations/ntfy.ts | |
| download | posthook-6bf57766feb8321f860baf300140563cd9539053.tar.gz posthook-6bf57766feb8321f860baf300140563cd9539053.zip | |
Init
Diffstat (limited to 'src/integrations/ntfy.ts')
| -rw-r--r-- | src/integrations/ntfy.ts | 40 |
1 files changed, 40 insertions, 0 deletions
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<IEither<Error, void>> { + if (!config.enabled || !config.server || !config.topic) { + return Either.right(<void>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(<void>undefined); + } catch (err) { + return Either.left(err instanceof Error ? err : new Error(String(err))); + } +} |
