Notification Adapter
The notification adapter implements a real-time socket-based messaging services from a system to users, using MongoDB as a data store.
Features
- Receiving Notifications
- Users can receive real-time notifications via email, SNS, or socket communication from system admins and other microservices.
- Topic management
- Topics can be created and organized to group notifications. For example, a topic can be created to send messages relating to new product releases or sales information.
- Subscription management
- Users can choose to subscribe to a specific topic. This lets them receive notifications relevant to them.
- Storing message history
- Message history can be saved, and users can view and search previous messages.
Installation
- Prerequisites
Dependency | Version |
---|---|
node | 18+ |
MongoDB | 5+ |
Nodeblocks User Service | 2.4.1+ |
Nodeblocks Org Service | 2.1.2+ |
- Install Package
Create your repository and add this package as a dependency
mkdir my-notification-service
npx gts init -y
npm install --save @basaldev/blocks-messaging-service
You will need to also set up your environment variables. Look at Quick Start Guide for a sample.
- Initial code
Place the following into src/index.ts:
import {
createNodeblocksMessagingApp,
defaultNotification,
} from '@basaldev/blocks-messaging-service';
import { getEnvString } from '../helper/utilities';
async function main() {
const adapter = await defaultNotification.createNotificationDefaultAdapter(
{
authEncSecret: getEnvString('AUTH_ENC_SECRET', ''),
authSignSecret: getEnvString('AUTH_SIGN_SECRET', ''),
sender: 'test',
},
{
db: getEnvString('DATABASE_URL', ''),
mailService: {
sendGridApiKey: getEnvString('SEND_GRID_API_KEY', ''),
},
userAPI: getEnvString('USER_ENDPOINT', ''),
}
);
await createNodeblocksMessagingApp({
corsOrigin: [/.*/],
}).startService({
PORT: Number(getEnvString('NOTIFICATION_PORT', '8081')),
adapter,
env: 'development',
});
}
void main();