2020-11-28 - User Contact Manager - Functions
Service - User Contact Manager
Lambda Functions
ContactMethodCreated
/**
* Triggered when a contact method handler creates a new contact
* @param {string} userId
* @param {string} methodTag
* @param {string} uniqueId
* @param {string} contactTag
*
*/
HdrSqs
Validator:
- userId cannot be empty string
- methodTag cannot be empty string
- uniqueId cannot be empty string
- contactTag cannot be empty string
logic
- put record into UserContacts table
- send message to OutUserContactCreated topic:
- userId = {userId}
- methodTag = {methodTag}
- uniqueId = {uniqueId}
- contactTag = {contactTag}
CreateNotificationGroup
/**
*
* @param {string} userId
* @param {string} userContactId
* @param {string} notificationGroupName
* @param (boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {boolean} consolidatedSendIfEmpty
*
* @returns {string} notificationGroupUniqueId
*/
HdrApi
Authorizer: User level
Validator:
- targetUserId cannot be empty string
- userContactId cannot be empty string
handler logic
when invoking createNotificationGroup targetUserId => userId param
logic
- get matching UserContacts record, if none return error to client Save into userContact variable
- explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
- create notificationGroupUniqueId = userContactId + "_" + new uuid
- send message to Service - Notification Manager InCreateNotificationGroup topic:
- receiverTag = {methodTag}
- groupingId = {userId}
- uniqueId = {notificationGroupUniqueId}
- notificationGroupName = {notificationGroupName}
- consolidated = {consolidated}
- consolidatedType = {consolidatedType}
- consolidatedFrequency = {consolidatedFrequency}
- consolidatedSendIfEmpty = {consolidatedSendIfEmpty}
- additionalData = object {userId: userId}
- return notificationGroupUniqueId
CreateNotifications
/**
*
* @param {string} userId
* @param {string} userContactId
* @param {string} notificationGroupUniqueId
* @param {Object[]} notifications
* @param {string} [notifications.notificationName]
* @param {Object[]} notifications.triggers
* @param {string} [notifications.triggers.propertyName]
* @param {string} notifications.triggers.valueType - property|attribute|serviceName|topicName
* @param {string} [notifications.triggers.value] - either value or values will be set
* @param {string[]} [notifications.triggers.values] - either value or values will be set
*
*/
HdrApi
Authorizer: User level
Validator:
- targetUserId cannot be empty string
- userContactId cannot be empty string
- notificationGroupUniqueId cannot be empty string
- notifications cannot be an empty array? Can limit number of notifications in array?
handler logic
when invoking createNotifications targetUserId => userId param
logic
- get matching UserContacts record, if none return error to client. Save into userContact variable
- explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
- send message to Service - Notification Manager InCreateNotifications topic:
- receiverTag = {methodTag}
- groupingId = {userId}
- uniqueId = {notificationGroupUniqueId}
- notifications = {notifications}
UpdateNotificationGroup
/**
* Updates one notification group
* @param {string} userId
* @param {string} userContactId
* @param {string} notificationGroupUniqueId
* @param {string} notificationGroupName
* @param {boolean} consolidated
* @param {string} consolidatedType
* @param {..?} consolidatedFrequency
* @param {boolean} consolidatedSendIfEmpty
* @param {boolean} enabled
*
*/
HdrApi
Authorizer: User level
Validator:
- targetUserId cannot be empty string
- userContactId cannot be empty string
- notificationGroupUniqueId cannot be empty string
handler logic
targetUserId > userId param
logic
- get matching UserContacts record, if none return error to client. Save into userContact variable
- explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
- send message to Service - Notification Manager InUpdateNotificationGroup topic:
- receiverTag = {methodTag}
- groupingId = {userId}
- uniqueId = {notificationGroupUniqueId}
- notificationGroupName
- consolidated
- consolidatedType
- consolidatedFrequency
- consolidatedSendIfEmpty
- enabled
DisableNotifications
/**
*
* @param {string} userId
* @param {string} userContactId
* @param {string} notificationGroupUniqueId
* @param {string[]} notificationIds
*
*/
HdrApi
Authorizer: User level
Validator:
- targetUserId cannot be empty string
- userContactId cannot be empty string
- notificationGroupUniqueId cannot be empty string
- notificationIds cannot be an empty array? Can limit number of notificationIds in array?
handler logic
when invoking disableNotifications targetUserId => userId param
logic
- get matching UserContacts record, if none return error to client. Save into userContact variable
- explode userContactId using #explodeUserContactId to get methodTag and uniqueId variables
- send message to Service - Notification Manager InDisableNotifications topic:
- receiverTag = {methodTag}
- groupingId = {userId}
- uniqueId = {notificationGroupUniqueId}
- notificationIds = {notificationIds}
ContactMethod/List
/**
* Lists all available contact methods for User Contact Manager service
*
* @returns {Object[]} array of objects, each object is one available contact method
*/
HdrApi
Authorizer: App level
Validator:
- (none)
handler logic
(none)
logic
Query Config table for all ContactMethodServiceName records and return. Client will link to Create endpoint when choose to create a new user contact for a contact method.
UserContact/List
/**
* Lists all available user contacts for one user
* @param {string} userId
*
* @returns {Object[]} array of objects, each object is one user contact
*/
HdrApi
Authorizer: App level
Validator:
- targetUserId
handler logic
targetUserId becomes userId param
logic
Query UserContacts table for all records that match userId and return.
Functions
createUserContactId
/**
* Creates userContactId from its elements
* @param {string} methodTag
* @param {string} uniqueId
*
* @returns {string} userContactId
*/
module: libs/UserContacts
logic
- Concatenate methodTag + "_" + uniqueId
explodeUserContactId
/**
* Explodes userContactId into its elements
* @param {string} userContactId
*
* @returns {string[]} methodTag and uniqueId
*/
module: libs/UserContacts
logic
- Explode userContactId using "_"
- Check count of elements = 2
- return array of elements