Typescript Aasaanjobs NotificationHub Client
Typescript SDK to communicate with Aasaanjobs Notification Hub and send notifications to users.
Supported Notification Channels
- Short Messaging Service (SMS)
- Mobile Push (FCM)
Installation
npm install <package-name>
Local Testing
Export environment variable as shown in the sample notification below. And run -
npm run test
Publishing
Log in to npm account on local using -
npm login
To publish a beta version for dev testing or QA -
Update the version in package.json to <version>-beta.<number>. And run -
npm publish --tag beta
To publish a release version, update version in package.json to actual release version and run -
npm publish
Usage
Each notification is referred to as Task in this library. A single Task can contain multiple channels, i.e., a single Task can contain both Email and WhatsApp notification data. This Task is then validated via Protocol Buffers and pushed to corresponding Notification Hub Amazon SQS queue.
SQS Options Interface - It needs to be configured with appropriate options for the type of notification to be sent.
interface ISQSOptions {
queueUrl?: string
marketingQueueUrl?: string
otpQueueUrl?: string
accessKeyId: string
secretAccessKey: string
region?: string
}
Task Interface - To add notification task for each channel.
interface ITasks {
email?: EmailTask
sms?: SMSTask
whatsapp?: WhatsAppTask
push?: PushTask
}
Task Constructor - Available options to initialize the Task object.
constructor(
sqsOptions: ISQSOptions,
name: string,
sentById: string,
client: string,
platform: NotificationTask.Platform,
messageType: NotificationTask.MessageType,
tasks: ITasks,
waterfallType?: NotificationTask.WaterfallMode
)
Sample Notification Task to send an SMS:
import { uuid } from 'uuidv4'
import { Task, ISQSOptions, ITasks, SMSTask, Platform, MessageType, WaterfallMode, Waterfall } from 'notification-hub-js-sdk'
let template = "https://static.aasaanjobs.com/sms_template.html"
let mobile = "1234567890"
let userId = uuid().toString()
let waterfall = new Waterfall()
waterfall.setPriority(1)
waterfall.setOffsettime(60)
let sms = new SMSTask(template, mobile, userId, waterfall)
let sqsOptions: ISQSOptions = {
queueUrl: process.env.QUEUE_URL || "",
marketingQueueUrl: process.env.MARKETING_QUEUE_URL || "",
otpQueueUrl: process.env.OTP_QUEUE_URL || "",
accessKeyId: process.env.SQS_ACCESS_KEY || "",
secretAccessKey: process.env.SQS_SECRET_KEY || "",
region: process.env.SQS_REGION
}
let name = "Test SMS"
let sentById = uuid().toString()
let client = "JS SDK Test Client"
let platform = Platform.OLXPEOPLE
let messageType = MessageType.MARKETING
let waterfallType = WaterfallMode.AUTO
let tasks: ITasks = {
sms: getSMSTask()
}
let task = new Task(sqsOptions, name, sentById, client, platform, messageType, tasks, waterfallType)
task.send()
Requirements
Each application which uses this library must configure Amazon SQS configurations to successfully send notification task to Hub.
interface ISQSOptions {
queueUrl?: string
marketingQueueUrl?: string
otpQueueUrl?: string
accessKeyId: string
secretAccessKey: string
region?: string
}
For Transactional notifications queueUrl should be provided.
For Marketing notifications marketingQueueUrl should be provided.
For OTP notifications otpQueueUrl should be provided.
SQS options accessKeyId, secretAccessKey, region are required.