Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/notifications/channels/channel.interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import { Notification } from '../entities/notification.entity';
import { EventType } from '../enums/event-type.enum';
import { DeliveryChannel } from '../interfaces/notification.types';

export interface RenderedNotificationPayload {
userId: string;
channel: DeliveryChannel;
rendered: {
title?: string;
subject?: string;
body: string;
html?: string;
markdown?: string;
actionUrl?: string;
};
eventType: EventType;
metadata: Record<string, any>;
}

export interface ChannelDeliveryResult {
success: boolean;
error?: string;
deliveryTimestamp?: Date;
channelMessageId?: string; // Channel-specific message ID for tracking
}

/**
* NotificationChannel
*
* Base interface for all notification delivery channels.
* Implementations handle the specifics of their delivery mechanism
* (email, push, webhook, etc.) while conforming to this contract.
*/
export interface NotificationChannel {
/**
* Unique identifier for the channel
Expand All @@ -19,11 +43,23 @@ export interface NotificationChannel {

/**
* Send a notification through this channel
* @param payload Rendered notification with user context and metadata
* @returns Delivery result with success status and optional error message
*/
send(notification: Notification): Promise<ChannelDeliveryResult>;
send(payload: RenderedNotificationPayload): Promise<ChannelDeliveryResult>;

/**
* Validate user configuration for this channel
* @returns { valid: boolean, errors: string[] }
*/
validateConfig(userId: string): Promise<{ valid: boolean; errors: string[] }>;

/**
* Optional: Get channel-specific metrics
*/
getMetrics?(): Promise<{
successCount: number;
failureCount: number;
averageDeliveryTimeMs: number;
}>;
}
Loading