@kasifraza/nestjs-notification
v1.0.0
Published
Multi-channel notification service for NestJS (email, slack, webhook, in-app)
Maintainers
Readme
@kasifraza/nestjs-notification
Multi-channel notification service for NestJS (email, slack, webhook, in-app).
Installation
npm install @kasifraza/nestjs-notificationUsage
Module Registration
import { NotificationModule, InAppProvider, SlackProvider, EmailProvider } from '@kasifraza/nestjs-notification';
@Module({
imports: [
NotificationModule.register({
channels: {
'in-app': new InAppProvider(),
'slack': new SlackProvider('https://hooks.slack.com/services/...'),
'email': new EmailProvider(async (notification) => {
// custom send logic
return { success: true, messageId: '123' };
}),
},
defaultChannel: 'in-app',
}),
],
})
export class AppModule {}Sending Notifications
import { NotificationService } from '@kasifraza/nestjs-notification';
@Injectable()
export class OrderService {
constructor(private readonly notifications: NotificationService) {}
async notifyUser() {
// Single notification
await this.notifications.send({
channel: 'in-app',
recipient: 'user-123',
subject: 'Order Confirmed',
body: 'Your order has been confirmed.',
});
// Send to multiple channels
await this.notifications.sendToAll(['in-app', 'email'], {
recipient: 'user-123',
subject: 'Order Shipped',
body: 'Your order is on the way!',
});
}
}Providers
| Provider | Description |
|----------|-------------|
| InAppProvider | Stores notifications in memory |
| EmailProvider | Send via custom function or API endpoint |
| SlackProvider | Post to Slack webhook URL |
| WebhookProvider | POST to any webhook URL |
Author
Kasif Raza - kasif-raza.vercel.app
License
MIT
