Notif-Sender-NestJS is a notification service built for NestJS applications. It provides an easy way to send notifications via Email and Telegram, with built-in queue management using RxJS
for better scalability.
- ✅ Send Email notifications using SMTP
- ✅ Send Telegram messages to a bot
- ✅ Built-in queue management using
RxJS
- ✅ Designed for scalability and easy integration into NestJS projects
- ✅ Limit the maximum number of concurrent requests for sending notifications
Notif-Sender uses RxJS
to queue and manage notifications, ensuring that messages are sent efficiently without blocking the main thread. This is useful for handling large volumes of notifications.
This example demonstrates how to use notif-sender-nestjs
for sending emails in a NestJS application.
Make sure you have installed the required package:
npm install notif-sender-nestjs
Or if you use pnpm
:
pnpm add notif-sender-nestjs
Import NotifSenderModule
in your module and configure it as follows:
import { NotifSenderModule } from 'notif-sender-nestjs'
@Module({
imports: [
NotifSenderModule.register({
emailSenderConfig: {
enable: boolean,
host: 'string',
port: number,
secure: boolean,
auth: {
user: 'string',
pass: '******',
},
default: {
from: 'string', // optional
},
maxConcurrentRequests: number // default is 2
},
telegramSenderConfig: {
enable: boolean,
botToken: 'string',
chatId: 'string',
maxConcurrentRequests: number // default is 2
},
logging: {
enable: true // default is true!
}
}),
],
controllers: [ AppController ],
providers: [ AppService ],
})
export class AppModule {}
This service provides four methods for sending notifications via Telegram or email:
💥 sendNotifToEmail : Sends an email immediately. Use this when you need to ensure the email is sent before continuing execution.
🗃️ sendNotifToEmail_addToQueue : Queues the email for later sending. This is useful when you don't need an immediate response and just want the email to be processed asynchronously.
💥 sendNotifToTelegram : The sendNotifToTelegram
method sends notifications directly to the chat ID configured during setup. However, you can also specify a different chat ID when calling this method.
🗃️ sendNotifToTelegram_addToQueue : This method works similarly to sendNotifToTelegram
, but instead of sending the notification immediately, it adds it to a queue and sends it in order
Inject NotifSenderService
into your service and send an email as follows:
import { NotifSenderService } from 'notif-sender-nestjs'
@Injectable()
export class AppService {
constructor(private readonly notifService: NotifSenderService) {}
async getHello()
{
// Send to email
await this.notifService.sendNotifToEmail({
subject: 'Hello',
text: 'Hello World!',
to: '[email protected]',
html: '<p>Hello World!</p>',
from: 'Abolfazl Ghaderi <abolfazlghaderi.ir>' // Optional - higher priority
})
// Send to telegram
await this.notifService.sendNotifToTelegram({
text: 'Hi mr.Brian',
chatId: 'string', // Optional - higher priority
})
return 'Hello World!'
}
// OR
getHello()
{
// Send to email
this.notifService.sendNotifToEmail_addToQueue({
subject: 'Hello',
text: 'Hello World!',
to: '[email protected]',
html: '<p>Hello World!</p>',
from: 'Abolfazl Ghaderi <abolfazlghaderi.ir>' // Optional - higher priority
})
// Send to telegram
this.notifService.sendNotifToTelegram_addToQueue({
text: 'Hi mr.Brian',
chatId: 'string', // Optional - higher priority
})
return 'Hello World!'
}
}
Got any questions or suggestions? Feel free to reach out ❤️
🌐 Website: abolfazlghaderi.ir
📩 Email: [email protected]
💬 Telegram: @Abolfazl_ghaderii
Let's build something amazing together! ✨