71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
/**
|
|
* Infrastructure Adapter: DiscordNotificationAdapter (Stub)
|
|
*
|
|
* Handles Discord webhook notifications.
|
|
* Currently a stub - to be implemented when Discord integration is needed.
|
|
*/
|
|
|
|
import type {
|
|
NotificationDeliveryResult,
|
|
NotificationGateway
|
|
} from '@core/notifications/application/ports/NotificationGateway';
|
|
import type { Notification } from '@core/notifications/domain/entities/Notification';
|
|
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
|
|
|
|
export interface DiscordAdapterConfig {
|
|
webhookUrl?: string;
|
|
}
|
|
|
|
export class DiscordNotificationAdapter implements NotificationGateway {
|
|
private readonly channel: NotificationChannel = 'discord';
|
|
private webhookUrl: string | undefined;
|
|
|
|
constructor(config: DiscordAdapterConfig = {}) {
|
|
this.webhookUrl = config.webhookUrl;
|
|
}
|
|
|
|
async send(notification: Notification): Promise<NotificationDeliveryResult> {
|
|
if (!this.isConfigured()) {
|
|
return {
|
|
success: false,
|
|
channel: this.channel,
|
|
error: 'Discord webhook URL not configured',
|
|
attemptedAt: new Date(),
|
|
};
|
|
}
|
|
|
|
// TODO: Implement actual Discord webhook call
|
|
// For now, this is a stub that logs and returns success
|
|
console.log(`[Discord Stub] Would send notification to ${this.webhookUrl}:`, {
|
|
title: notification.title,
|
|
body: notification.body,
|
|
type: notification.type,
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
channel: this.channel,
|
|
externalId: `discord-stub-${notification.id}`,
|
|
attemptedAt: new Date(),
|
|
};
|
|
}
|
|
|
|
supportsChannel(channel: NotificationChannel): boolean {
|
|
return channel === this.channel;
|
|
}
|
|
|
|
isConfigured(): boolean {
|
|
return !!this.webhookUrl;
|
|
}
|
|
|
|
getChannel(): NotificationChannel {
|
|
return this.channel;
|
|
}
|
|
|
|
/**
|
|
* Configure the webhook URL
|
|
*/
|
|
setWebhookUrl(url: string): void {
|
|
this.webhookUrl = url;
|
|
}
|
|
} |