2020-11-28 - Contact Method Email - Functions

From Izara Wiki
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

handler logic

  1. event will be array of messages, each message will be in notification object format
  2. (record property name) => (function parameter name):
    1. additionalData.userId => userId
    2. additionalData.emailUniqueId => uniqueId

logic

  1. get from email table record that matches userId and uniqueId, put into variable emailRecord
  2. if none found add warning log and return
  3. send email:
    1. stringify notificationBody
    2. send to emailRecord.email
    3. 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.

  1. get from email table record that matches userId and uniqueId, put into variable emailRecord
  2. if none found add warning log and return
  3. update Emails record
  4. if enabled setting changes from true to false send message to Service - Notification Manager InDisableNotificationGroups topic:
    1. receiverTag = {process.env.izServiceName}
    2. groupingId = {userId}
    3. 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

  1. validate email using https://www.npmjs.com/package/email-validator (maybe in validator)
  2. if does not pass validation return error to client (maybe in validator)
  3. create new uuid for uniqueId
  4. put record into Emails table
  5. send message to Service - User Contact Manager InContactCreated topic:
    1. userId = {userId}
    2. methodTag = {process.env.izServiceName}
    3. uniqueId = {uniqueId}
    4. contactTag = {contactTag}

Functions

....

/**
 * .......
 * @param {string} ...
 *
 * @returns {string} ...
 */

logic

  1. ...