2020-11-08 - Notification Manager - Functions
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} activityMsg
* @param {Object} activityMsg.messageAttributes
* @param {Object} activityMsg.message
* @param {String} uniqueId - In NotificationMgr, uniqueId is notificationId
* @param {number} time
*
*/
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
- putItem to ConsolidationPending table
- notificationGroupId
- time: {timestamp activity handled in Activity Switchboard}_{small random UUID}
- activityMsg
- putItem to ConsolidationPending table
- else
DisableNotificationGroups
/**
* Disables a set of matching notification groups
* @param {string} userId
* @param {string} userContactId
*
*/
HdrSqs
Subscribes to InDisableNotificationGroups topic
logic
- get notificationGroup node by GraphHandler getNodeAndRelationships
- nodeLabel: "userContact"
- nodeProperties.userContactId
- relationshipType: "has_notificationGroup"
- relationshipDirection: "outgoing"
- if not found notificationGroup or notification node
- throw new NoRetryError
- else
- for each notificationGroup
- use function #disableNotificationGroup
UpdateNotificationGroup
/**
* Update a notification group
* @param {string} userId
* @param {string} notificationGroupId
* @param {string} notificationGroupName
* @param {boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {number} consolidatedNextSendDue
* @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" or "disabled_notification" (depend on enable)
- relationshipDirection: "outgoing"
- if not found notificationGroup or notification node
- throw new NoRetryError
- else update notificationGroup node by send message to Service - Graph Handler InCreateVersionedData
- nodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- versionDataStructure
- nodeLabel: "notificationGroupSetting"
- nodeProperties: {notificationGroupName, consolidated, consolidatedType, consolidatedFrequency, consolidatedNextSendDue, consolidatedSendIfEmpty}
- nodeStructure
- if enabled = false
- use function #disableNotificationGroup
- if enabled = true
DisableNotification
/**
* @param {string} userId
* @param {string} notificationId
*
*/
HdrSqs
Subscribes to InDisableNotification topic
logic
- get notification node by GraphHandler getNodeAndRelationships
- nodeLabel: "notification"
- nodeProperties.notificationId
- relationshipType: "has_notification"
- relationshipDirection: "incoming"
- if not found notification node
- throw new NoRetryError
- change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
- send message to Service - Activity Switchboard InRemoveTriggerGroup
- receiverTag: process.env.iz_serviceName
- notificationId
- send message to OutNotificationDisabled topic
- notificationId
CreateNotificationGroup
/**
* Creates one notification group
* @param {string} userId
* @param {string} notificationGroupName
* @param {boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {number} consolidatedNextSendDue
* @param {boolean} consolidatedSendIfEmpty
* @param {string} recieverTag
*
*/
HdrSqs
Subscribes to InCreateNotificationGroup topic
logic
- create notificationGroupId by random UUID
- if !consolidate set consolidate is false
- create versionedDataProperties object
- consolidate
- if consolidated = true, validate:
- consolidatedType must equal "overview" or "detailed"
- consolidatedSendIfEmpty set default is "false"
- consolidatedFrequency ..? (not sure, maybe use some sort of standard like cron)
- if have notificationGroupName save it to versionedDataProperties
- versionedDataProperties: {notificationGroupName, consolidated, consolidatedType, consolidatedFrequency, consolidatedNextSendDue, consolidatedSendIfEmpty}
- create notificationGroup by send message to Service - Graph Handler InCreateNodeWithVersionedData
- nodeStructure
- nodeLabel: "notificationGroup"
- nodeProperties: {notificationGroupId, recieverTag}
- versionedDatas
- nodeLabel: "notificationGroupSettings"
- nodeProperties: versionedDataProperties
- nodeStructure
- send message to OutNotificationGroupCreated topic, can include full notificationGroup object
CreateNotification
/**
* Creates notification
* @param {string} userId
* @param {string} notificationGroupId
* @param {string} notificationName
*
*/
HdrSqs
Subscribes to InCreateNotification topic
logic
- create notificationId by random UUID
- if notification have notificationName
- send message to Service - Graph Handler InCreateChildNodeWithVersionedData
- else
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
CreateNotificationTrigger
/**
* Creates notificationTrigger
* @param {string} userId
* @param {string} notificationId
* @param {string} propertyName
* @param {string} valueType - property|attribute|serviceName|topicName
* @param {string} [valueString] - either value or values will be set
* @param {number} [valueNumber] - either value or values will be set
* @param {string[]} [values] - either value or values will be set
*
*/
HdrSqs
Subscribes to InCreateNotificationTrigger topic
logic
- create notificationTriggerId by random UUID
- #notificationTriggerValidator
- if validateResult is "error"
- send message to OutCreateNotificationTriggerFailed
- notificationTriggerId
- errorsFound: {errorsFound}
- send message to OutCreateNotificationTriggerFailed
- if validateResult is "error"
- send message to Service - Graph Handler InCreateChildNodeAndRelationship
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 userContact node (in future; will have another service eg. SMS, site notification)
- send message to OutNewNotification topic, adding below properties:
- uniqueId
- notificationBody
- (? 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
/**
* Send message to receiver endpoint
* @param {Object} notificationId
* @param {Array} notificationTriggers
*/
logic
- send message to ActySwichboardTestInCreateTriggerGroup topic, adding below properties:
- receiverTag: {process.env.iz_serviceName}
- uniqueId: {notificationId}
- requestedTriggers: notificationTriggers
notificationTriggerValidator
/**
* Validate notificationTrigger
* @param {Object} notificationTrigger
* @param {string} notificationTrigger.propertyName - optional
* @param {string} notificationTrigger.valueType - require
* @param {string} notificationTrigger.valueString - optional
* @param {number} notificationTrigger.valueNumber - optional
* @param {Array} notificationTrigger.values - optional
*
* @returns {Array}
*/
logic
- vatidate notificationTrigger (see. Service - Notification Manager) collect error and return status
- notificationTrigger must have only one of those ["valueString", "valueNumber", "values"]
- "serviceName" and "topicName" valueTypes do not have propertyName
- validate type of properties ["valueString", "valueNumber", "values"]
- - typeof "valueString" is string
- - typeof "valueNumber" is number
- - typeof "values" is array
- return
- validateStatus: {"complete" or "error"}
- errorsFound[ ]
reformNotificationTrigger
/**
* Reform notificationTriggers for send to InCreateTriggerGroup
* @param {Object[]} notificationTriggers
*
* returns {Object[]}
*/
logic
- for each notificationTrigger of notificationTriggers
- notificationTrigger must have nodeLabels and nodeLabels is "notificationTrigger"
- notificationTrigger must have nodeProperties
- use nodeProperties for #notificationTriggerValidator
- if error; throw new NoRetryError
- push nodeProperties to notificationTriggerReformed[ ]
- return notificationTriggerReformed[ ]
disableNotificationGroup
/**
* @param {Object} notificationGroup
* @param {string} userId
* @param {string} userContactId - default = null
*
*/
logic
- for each notificationId
- change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
- send message to Service - Activity Switchboard InRemoveTriggerGroup
- receiverTag
- notificationId
- send message to OutNotificationDisabled topic
- notificationId
- if !userContactId
- get notificationGroup node by GraphHandler getNodeAndRelationships for find userContact node
- nodeLabel: "notificationGroup"
- nodeProperties.notificationGroupId
- relationshipType: "has_notificationGroup"
- relationshipDirection: "incoming"
- get notificationGroup node by GraphHandler getNodeAndRelationships for find userContact node
- change relationshipType to "disabled_notificationGroup" by send message to Service - Graph Handler InChangeRelationshipType
- send message to OutNotificationGroupDisabled topic
- notificationGroupId
enableNotificationGroup
/**
* @param {Object} notificationGroup
* @param {string} userId
*
*/
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
- use child notificationTriggers for #reformNotificationTrigger
- use function sharedCreateTriggerGroup.sharedCreateTriggerGroup
- send message to Service - Activity Switchboard InCreateTriggerGroup
- uniqueId: notificationId
- 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
}
},
],
uniqueId: {emailId}
}