Service - Notification Manager
Jump to navigation
Jump to search
Service - Notification Manager
Lambda Functions
RcvActivityMsg
/**
* Receives one activity message from Activity Switchboard, find matching notification, stores for consolidation or sends immediately
* @param {Object[]} event.activityMsg
* @param {Object} event.activityMsg.messageAttributes
* @param {Object} event.activityMsg.message
* @param {String} event.uniqueId - In NotificationMgr, uniqueId is notificationId
* @param {Object[]} event.additionalData - additional params set in the trigger group
* @param {number} event.time
* @param {string} event.additionalData.notificationId - matches notificationId in notifications table
*
*/
HdrSqs
Subscribes to Service - Activity Switchboard OutTriggerGroupPassed topic, (? filter policy limit) receiverTag = {this service's izServiceName}
logic
- get notification node by getNodeAndRelationship
- nodeLabel: "notification"
- nodeProperties.notificationId
- relationshipType: "has_notification"
- relationshipDirection: "incoming"
- toNodeVersionedDataLabels: ["notificationGroupSettings"]
- if not found notification or notificationGroup node
- throw new NoRetryError
- If have setting and consolidated = true
- save activityMsg to ConsolidationPending table
- else
- invoke #sendNotificationToReceiver
DisableNotificationGroups
/**
* Disables a set of matching notification groups
* @param {string} notificationGroupId - null if not supplied
*
*/
HdrSqs
Subscribes to InDisableNotificationGroups topic
logic
- get notificationGroup node by GraphHandler getNodeAndRelationships
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- relationshipType: "has_notification"
- relationshipDirection: "outgoing"
- if not found notificationGroup or notification node
- throw new NoRetryError
- else
- get notificationId for each child notification node
- invoke #disableNotificationGroup
UpdateNotificationGroup
/**
* Update a notification group
* @param {string} notificationGroupId
* @param {string} notificationGroupName
* @param {boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {boolean} consolidatedSendIfEmpty
* @param {boolean} enabled
*
*/
HdrSqs
Subscribes to InUpdateNotificationGroup topic
logic
- get notificationGroup node by GraphHandler getNodeAndRelationships
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- relationshipType: "has_notification"
- relationshipDirection: "outgoing"
- if not found notificationGroup or notification node
- throw new NoRetryError
- else
- get notificationId for each child notification node
- update notificationGroup node by send message to Service - Graph Handler InCreateVersionedData
- nodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- versionDataStructure
- nodeLabel: "notificationGroupSetting"
- nodeProperties: {notificationGroupName, consolidated, consolidatedType, consolidatedFrequency, consolidatedSendIfEmpty}
- nodeStructure
- if enabled = false
- invoke #disableNotificationGroup
- if enabled = true
- invoke #enableNotificationGroup
DisableNotifications
/**
* Disables a set of matching notification groups
* @param {string[]} notificationIds
*
*/
HdrSqs
Subscribes to InDisableNotifications topic
logic
- for each notificationIds
- change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
- send message to Service - Activity Switchboard InRemoveTriggerGroup
- notificationId
- send message to OutNotificationDisabled topic
- notificationId
CreateNotificationGroup
/**
* Creates one notification group
* @param {string} notificationGroupId
* @param {string} notificationGroupName
* @param {boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {boolean} consolidatedSendIfEmpty
* @param {Object} additionalData
*
*/
HdrSqs
Subscribes to InCreateNotificationGroup topic
Validator:
- notificationGroupId cannot be empty string
logic
- if consolidated = true, validate:
- consolidatedType must equal "overview"|"detailed"
- consolidatedFrequency ..?
- consolidatedSendIfEmpty, set to false if not boolean and set to true
- create notificationGroup by send message to Service - Graph Handler InCreateNodeWithVersionedData
- nodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties: {notificationGroupId, additionalData}
- versionedDatas
- nodeLabel: "notificationGroupSetting"
- nodeProperties: {notificationGroupName, consolidated, consolidatedType, consolidatedFrequency, consolidatedSendIfEmpty}
- nodeStructure
- send message to OutNotificationGroupCreated topic, can include full notificationGroup object
CreateNotifications
/**
* Creates muti notifications
* @param {string} userId
* @param {string} notificationGroupId
* @param {Object[]} notifications
* @param {string} [notifications.notificationName]
* @param {Object[]} notifications.triggers
* @param {string} notifications.triggers.propertyName
* @param {string} notifications.triggers.valueType - property|attribute
* @param {string} [notifications.triggers.value] - either value or values will be set
* @param {string[]} [notifications.triggers.values] - either value or values will be set
*
*/
HdrSqs
Subscribes to InCreateNotifications topic
Validator:
- notificationGroupId cannot be empty string
- notifications cannot be an empty array? Can limit number of notifications in array?
logic
- get notificationGroup node by invoke graphSharedLib.getNode
- nodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties: {notificationId}
- versionedDataLabels: ["notificationGroupSetting"]
- nodeStructure
- if not found notificationGroup node
- send message to OutCreateNotificationsFailed topic
- notificationGroupId
- notifications
- errorsFound: "NotificationGroupNotFound"
- return
- send message to OutCreateNotificationsFailed topic
- for each notifications:
- create an object that contains
- notificationName
- triggers
- hash this object into variable named notificationId
- create child notification node and relationship
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
- parentNodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties: {notificationGroupId}
- createChildNodeStructure
- nodeStructure
- nodeLabel: "notification"
- nodePropertis: {notificationId}
- nodeStructure
- createRelationshipStructure
- relationshipStructure
- relationshipType: "has_notification"
- relationshipDirection: "outgoing"
- relationshipStructure
- parentNodeStructure
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
- for each notifications.triggers:
- create notificationTriggerId by {notificationId} + "_" + {randon UUID}
- create child notificationTrigger node and relationship
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
- parentNodeStructure
- nodeLabel: "notification"
- nodeProperties: {notificationId}
- createChildNodeStructure
- nodeStructure
- nodeLabel: "notificationTrigger"
- nodePropertis: {notificationTriggerId}
- nodeStructure
- createRelationshipStructure
- relationshipStructure
- relationshipType: "has_notificationTrigger"
- relationshipDirection: "outgoing"
- relationshipStructure
- parentNodeStructure
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
- create an object that contains 'notificationId' and 'triggers' for invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
- invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
- send message to Service - Activity Switchboard InCreateTriggerGroup topic
- uniqueId: {notificationId}
- additionalData: {}
- triggers: {notification.triggers}
- send message to Service - Activity Switchboard InCreateTriggerGroup topic
- send message to OutNotificationCreated topic, can include full notification object
- create an object that contains
NotificationGroup/List
/**
* Lists all notification groups for one primary key (notificationGroupId/uniqueId)
* @param {string} receiverTag
* @param {string} groupingId
* @param {string} [uniqueIdPrefix=null]
*
* @returns {Object[]} array of objects, each object is one notification group
*/
HdrApi
Validator:
- receiverTag
- groupingId
- uniqueIdPrefix with default value
handler logic
(standard)
logic
Query NotificationGroups table for all records that match notificationGroupId and if uniqueIdPrefix not null uniqueId starts_with uniqueIdPrefix, and return.
Functions
sendNotificationToReceiver
/**
* Send message to receiver endpoint
* @param {Object} notification - object from the Notifications table
* @param {Object} notificationGroup - object from the NotificationGroups table
* @param {string} notificationBody - string sent to receiver
*/
logic
- get notificationGroup node by getNodeAndRelationships
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- relationshipType: "has_notificationGroup"
- relationshipDirection: "incoming"
- return; notificationGroup and email node (in future; will have another service eg. SMS, site notification)
- send message to OutNewNotification topic, adding below properties:
- uniqueId: {emailId}
- notificationBody
- additionalData
- (? filter policy limit) receiverTag gets added to message attributes so can be filtered for by receiving service
- Service - User Contact Manager and Service - Contact Method Email will change logic or structure
disableNotificationGroup
/**
* @param {Object} notificationGroup
*
*/
logic
- for each notificationId
- change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
- send message to Service - Activity Switchboard InRemoveTriggerGroup
- notificationId
- send message to OutNotificationDisabled topic
- notificationId
- change relationshipType to "disabled_notificationGroup" by send message to Service - Graph Handler InChangeRelationshipType
- send message to OutNotificationGroupDisabled topic
- notificationGroupId
enableNotificationGroup
/**
* @param {Object} notificationGroup
*
*/
logic
- for each notificationId
- get notification node by GraphHandler getNodeAndRelationships
- nodeLabel: "notification"
- nodeProperties.notificationId
- relationshipType: "has_notificationTrigger"
- relationshipDirection: "outgoing"
- change relationshipType to "has_notification" by send message to Service - Graph Handler InChangeRelationshipType
- invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
- send message to Service - Activity Switchboard InCreateTriggerGroup
- uniqueId: notificationId
- additionalData: {}
- requestedTriggers: [{notificationTriggers}]
- send message to Service - Activity Switchboard InCreateTriggerGroup
- send message to OutNotificationEnabled topic
- notificationId
- get notification node by GraphHandler getNodeAndRelationships
- change relationshipType to "has_notificationGroup" by send message to Service - Graph Handler InChangeRelationshipType
- send message to OutNotificationGroupEnabled topic
- notificationGroupId
Sample notification object sent to receiver service
{
notificationBody: [
{
messageAttributes: {
// xxx: yyy
},
message: {
// full body of message received
}
},
],
additionalData: {
userId: ...
},
uniqueId: {emailId}
}