feat(notifications): add notification dispatch service

Refs: #74
This commit is contained in:
nocode committed 2026-09-13 12:25:06 +02:00
1 parent 6fca3b7ec4
commit 13f8e24e54
1 file changed
+33
@@ -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);
}