notif-sender-nestjs v0.2.4
š Notif-Sender NestJS
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.
Features
- ā 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
Queue Management with RxJS
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.
šŖ“ Usage
This example demonstrates how to use notif-sender-nestjs
for sending emails in a NestJS application.
š„ Installation
Make sure you have installed the required package:
npm install notif-sender-nestjs
Or if you use pnpm
:
pnpm add notif-sender-nestjs
š§āš» Configuration
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
},
},
telegramSenderConfig: {
enable: boolean,
botToken: 'string',
chatId: 'string',
}
}),
],
controllers: [ AppController ],
providers: [ AppService ],
})
export class AppModule {}
š Usage in Service
This service provides four methods for sending notifications via Telegram or email:
š§ 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.
šØ Telegram :
š„ 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.
ā ļø Important: Before sending a notification, the user must have already started a conversation with the bot; otherwise, the bot won't be able to send messages
šļø 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()
{
await this.notifService.sendNotifToEmail({
subject: 'Hello',
text: 'Hello World!',
to: 'dev.ghaderi@gmail.com',
html: '<p>Hello World!</p>'
})
// OR
await this.notifService.sendNotifToTelegram({
text: 'Hi mr.Brian',
chatId: 'string', // Optional
})
return 'Hello World!'
}
// OR
getHello()
{
this.notifService.sendNotifToEmail_addToQueue({
subject: 'Hello',
text: 'Hello World!',
to: 'dev.ghaderi@gmail.com',
html: '<p>Hello World!</p>'
})
// OR
this.notifService.sendNotifToTelegram_addToQueue({
text: 'Hi mr.Brian',
chatId: 'string', // Optional
})
return 'Hello World!'
}
}
š Feedback & Contact
Got any questions or suggestions? Feel free to reach out ā¤ļø
š© Email: dev.ghaderi@gmail.com
š¬ Telegram: @Abolfazl_ghaderii
š Website: abolfazlghaderi.ir
Let's build something amazing together! āØ