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);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user