2020-11-28 - Contact Method Email - Functions
Jump to navigation
Jump to search
Service - Contact Method Email
Lambda Functions
RcvNotification
/**
* Receives one notification from Notification Manager, finds matching Contact Method handler and passes on the notification
* @param {string} userId
* @param {string} uniqueId
* @param {Object} notificationBody
*
*/
HdrSqs
- Subscribes to Service - Notification Manager Out(..?) topic, (?..filter policy limit) filter receiverTag by process.env.izServiceName
handler logic
- event will be array of messages, each message will be in notification object format
- (record property name) => (function parameter name):
- additionalData.userId => userId
- additionalData.emailUniqueId => uniqueId
logic
- get from email table record that matches userId and uniqueId, put into variable emailRecord
- if none found add warning log and return
- send email:
- stringify notificationBody
- send to emailRecord.email
- not yet setup AWS service for sending emails
Email/Update
/**
* Updates one email record, available changes are contactTag and enabled setting
* @param {string} userId
* @param {string} uniqueId
* @param {string} contactTag
* @param {boolean} enabled
*
*/
HdrApi
- Use authenticator that matches submitted userId to tokens userId, rejects if do not match
Validator:
- contactTag cannot be empty string
logic
if changing from enabled = false to enabled = true do not send a message enabling notification groups, user needs to manually re-enable them, or we could add a setting to the request that chooses whether this is done automatically.
- get from email table record that matches userId and uniqueId, put into variable emailRecord
- if none found add warning log and return
- update Emails record
- if enabled setting changes from true to false send message to Service - Notification Manager InDisableNotificationGroups topic:
- receiverTag = {process.env.izServiceName}
- groupingId = {userId}
- uniqueIdPrefix = {process.env.izServiceName} + "_" + {uniqueId} + "_"
Email/Create
/**
* Creates one email record
* @param {string} userId
* @param {string} email
* @param {string} contactTag
* @param {boolean} [enabled=true]
*
*/
HdrApi
- Use authenticator that matches submitted userId to tokens userId, rejects if do not match
Validator:
- contactTag cannot be empty string
- maybe validate email address here? Or if not strong enough use email-validator npm module
logic
- validate email using https://www.npmjs.com/package/email-validator (maybe in validator)
- if does not pass validation return error to client (maybe in validator)
- create new uuid for uniqueId
- put record into Emails table
- send message to Service - User Contact Manager InContactCreated topic:
- userId = {userId}
- methodTag = {process.env.izServiceName}
- uniqueId = {uniqueId}
- contactTag = {contactTag}
Functions
....
/**
* .......
* @param {string} ...
*
* @returns {string} ...
*/
logic
- ...