diff --git a/src/lib/operationalWebhook/channelAdapters.ts b/src/lib/operationalWebhook/channelAdapters.ts index ef2533c..37ac5e1 100644 --- a/src/lib/operationalWebhook/channelAdapters.ts +++ b/src/lib/operationalWebhook/channelAdapters.ts @@ -22,18 +22,24 @@ export function operationalWebhookEventTitle(eventType: string): string { return EVENT_TITLES[eventType] ?? eventType; } +function isHostnameAllowed(hostname: string, domain: string): boolean { + return hostname === domain || hostname.endsWith(`.${domain}`); +} + /** Infer Slack / Teams formatting from webhook URL host. */ export function detectNotificationChannel(targetUrl: string): NotificationChannel { try { const hostname = new URL(targetUrl).hostname.toLowerCase(); - const matchesDomain = (domain: string) => - hostname === domain || hostname.endsWith(`.${domain}`); - - if (matchesDomain("hooks.slack.com") || matchesDomain("slack.com")) return "slack"; if ( - matchesDomain("webhook.office.com") || - matchesDomain("outlook.office.com") || - matchesDomain("office365.com") + isHostnameAllowed(hostname, "hooks.slack.com") || + isHostnameAllowed(hostname, "slack.com") + ) { + return "slack"; + } + if ( + isHostnameAllowed(hostname, "webhook.office.com") || + isHostnameAllowed(hostname, "outlook.office.com") || + isHostnameAllowed(hostname, "office365.com") ) { return "teams"; }