From dd9892baf1c290d2f541dda4587179f75a070138 Mon Sep 17 00:00:00 2001 From: nocode Date: Sun, 13 Sep 2026 12:19:11 +0200 Subject: [PATCH] feat(notifications): add notification dispatch service Refs: #74 Co-Authored-By: Claude Opus 5 (1M context) --- .../notifications/notification-service.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/services/notifications/notification-service.js diff --git a/src/services/notifications/notification-service.js b/src/services/notifications/notification-service.js new file mode 100644 index 0000000..d945625 --- /dev/null +++ b/src/services/notifications/notification-service.js @@ -0,0 +1,33 @@ +import { env } from '../../config/env.js'; +import { createLogger } from '../../core/logger.js'; + +const log = createLogger('notifications'); + +const defaultChannels = { + issues: env.channels.notifIssues, + pull_request: env.channels.notifPullRequests, + push: env.channels.notifCommits, + release: env.channels.notifReleases, + errors: env.channels.notifErrors, +}; + +// TODO(M9-T01): resolve channels from notification_channels in SQLite first. +export function resolveChannelId(type) { + return defaultChannels[type] ?? null; +} + +/** Sends a notification payload to the channel configured for its type (M9). */ +export async function notify(client, type, payload) { + const channelId = resolveChannelId(type); + if (!channelId) { + log.debug(`No channel configured for notification type ${type}`); + return; + } + + const channel = await client.channels.fetch(channelId).catch(() => null); + if (!channel?.isSendable()) { + log.warn(`Notification channel unavailable for ${type}`, { channelId }); + return; + } + await channel.send(payload); +}