Service - Notification Manager

From Izara Wiki
Revision as of 03:09, 12 July 2024 by Pong (talk | contribs)
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

  1. get notification node by getNodeAndRelationship
    • nodeLabel: "notification"
    • nodeProperties.notificationId
    • relationshipType: "has_notification"
    • relationshipDirection: "incoming"
    • toNodeVersionedDataLabels: ["notificationGroupSettings"]
  2. if not found notification or notificationGroup node
    • throw new NoRetryError
  3. If have setting and consolidated = true
    • save activityMsg to ConsolidationPending table
  4. else


DisableNotificationGroups

/**
 * Disables a set of matching notification groups
 * @param {string} notificationGroupId - null if not supplied
 *
 */

HdrSqs

Subscribes to InDisableNotificationGroups topic

logic

  1. get notificationGroup node by GraphHandler getNodeAndRelationships
    • nodeLabel: "notificationGroup"
    • nodeProperties.notificationGroupId
    • relationshipType: "has_notification"
    • relationshipDirection: "outgoing"
  2. if not found notificationGroup or notification node
    • throw new NoRetryError
  3. else
    • get notificationId for each child notification node
  4. 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

  1. get notificationGroup node by GraphHandler getNodeAndRelationships
    • nodeLabel: "notificationGroup"
    • nodeProperties.notificationGroupId
    • relationshipType: "has_notification"
    • relationshipDirection: "outgoing"
  2. if not found notificationGroup or notification node
    • throw new NoRetryError
  3. else
    • get notificationId for each child notification node
  4. 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}
  5. if enabled = false
    1. invoke #disableNotificationGroup
  6. if enabled = true
    1. invoke #enableNotificationGroup

DisableNotifications

/**
 * Disables a set of matching notification groups
 * @param {string[]} notificationIds
 *
 */

HdrSqs

Subscribes to InDisableNotifications topic

logic

  1. for each notificationIds
    1. change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
    2. send message to Service - Activity Switchboard InRemoveTriggerGroup
      • notificationId
    3. 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

  1. if consolidated = true, validate:
    1. consolidatedType must equal "overview"|"detailed"
    2. consolidatedFrequency ..?
    3. consolidatedSendIfEmpty, set to false if not boolean and set to true
  2. 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}
  3. 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

  1. get notificationGroup node by invoke graphSharedLib.getNode
    • nodeStructure
      • nodeLabel: "notificationGroup"
      • nodeProperties: {notificationId}
    • versionedDataLabels: ["notificationGroupSetting"]
  2. if not found notificationGroup node
    1. send message to OutCreateNotificationsFailed topic
      • notificationGroupId
      • notifications
      • errorsFound: "NotificationGroupNotFound"
    2. return
  3. for each notifications:
    1. create an object that contains
      • notificationName
      • triggers
    2. hash this object into variable named notificationId
    3. create child notification node and relationship
      1. send message to Service - Graph Handler InCreateChildNodeAndRelationship
        • parentNodeStructure
          • nodeLabel: "notificationGroup"
          • nodeProperties: {notificationGroupId}
        • createChildNodeStructure
          • nodeStructure
            • nodeLabel: "notification"
            • nodePropertis: {notificationId}
        • createRelationshipStructure
          • relationshipStructure
            • relationshipType: "has_notification"
            • relationshipDirection: "outgoing"
    4. for each notifications.triggers:
      1. create notificationTriggerId by {notificationId} + "_" + {randon UUID}
      2. create child notificationTrigger node and relationship
        1. send message to Service - Graph Handler InCreateChildNodeAndRelationship
          • parentNodeStructure
            • nodeLabel: "notification"
            • nodeProperties: {notificationId}
          • createChildNodeStructure
            • nodeStructure
              • nodeLabel: "notificationTrigger"
              • nodePropertis: {notificationTriggerId}
          • createRelationshipStructure
            • relationshipStructure
              • relationshipType: "has_notificationTrigger"
              • relationshipDirection: "outgoing"
    5. create an object that contains 'notificationId' and 'triggers' for invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
    6. invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
      1. send message to Service - Activity Switchboard InCreateTriggerGroup topic
        • uniqueId: {notificationId}
        • additionalData: {}
        • triggers: {notification.triggers}
    7. send message to OutNotificationCreated topic, can include full notification object

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

  1. 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)
  2. 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

  1. for each notificationId
    1. change relationshipType to "disabled_notification" by send message to Service - Graph Handler InChangeRelationshipType
    2. send message to Service - Activity Switchboard InRemoveTriggerGroup
      • notificationId
    3. send message to OutNotificationDisabled topic
      • notificationId
  2. change relationshipType to "disabled_notificationGroup" by send message to Service - Graph Handler InChangeRelationshipType
  3. send message to OutNotificationGroupDisabled topic
    • notificationGroupId

enableNotificationGroup

/**
 * @param {Object} notificationGroup
 *
 */

logic

  1. for each notificationId
    1. get notification node by GraphHandler getNodeAndRelationships
      • nodeLabel: "notification"
      • nodeProperties.notificationId
      • relationshipType: "has_notificationTrigger"
      • relationshipDirection: "outgoing"
    2. change relationshipType to "has_notification" by send message to Service - Graph Handler InChangeRelationshipType
    3. invoke sharedCreateTriggerGroup.sharedCreateTriggerGroup
      1. send message to Service - Activity Switchboard InCreateTriggerGroup
        • uniqueId: notificationId
        • additionalData: {}
        • requestedTriggers: [{notificationTriggers}]
    4. send message to OutNotificationEnabled topic
      • notificationId
  2. change relationshipType to "has_notificationGroup" by send message to Service - Graph Handler InChangeRelationshipType
  3. 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}
}