Skip to main content

Configuration

Initial Configuration

To use NotificationsModule, you need to setup the configuration first.

1. Create config/notification.ts

import {
EmailChannel,
GupshupSmsChannel,
NotificationOptions,
} from '@libs/notifications';
import { registerAs } from '@nestjs/config';

export default registerAs(
'notification',
() =>
({
isGlobal: true,
channels: {
mail: {
channelHandler: EmailChannel,
},
'gupshup:sms': {
channelHandler: GupshupSmsChannel,
host: process.env.GUPSHUP_HOST,
senderId: process.env.GUPSHUP_SENDER_ID,
apiKey: process.env.GUPSHUP_API_KEY,
appId: process.env.GUPSHUP_APP_ID,
},
},
} as NotificationOptions),
);

2. Register Async NotificationModule Add following snippet to the imports array. ConfigService is importable from @nestjs/config module

NotificationsModule.registerAsync({
isGlobal: false,
imports: [ConfigModule],
useFactory: (config: ConfigService) => config.get('notification'),
inject: [ConfigService],
})

Channel Configuration

GupshupSmsChannel

Use this channel to send SMS to the receipents.

Configuration

To use GupshupSmsChannel, you need a few keys to properly enable the channel. You can pass these keys as key:value pair in the configuration that we set up.

info

You can get these values from Gupshup Dashboard. If you don't have the access, reach out to your project manager to help you with the necessary information.

KeyDescription
hostHost of SMS Gupshup API
senderIdSenderId of your application in SMS Gupshup
apiKeyAPI Key of the App in SMS Gupshup
appIdApplication Identifier of the App in SMS Gupshup

Once the configuration is done, you can simply add the toGupshupSms method in your NotificationTemplate, and put your logic of building the payload there.

EmailChannel

To use EmailChannel, you need to setup @squareboat/nest-mailman in your application to properly enable the channel.

Once @squareboat/nest-mailman is installed, follow it's documentation to see how to configure and use the package. NotificationModule will use the globally initialised version of MailmanModule.

Once the configuration is done, you can simply add the toEmail method in your NotificationTemplate, and put your logic of building the payload there.