ems-backend icon indicating copy to clipboard operation
ems-backend copied to clipboard

Email notification system Phase 1

Open SianaDicheva opened this issue 1 year ago • 4 comments

Phase 1

  1. Creating Email Alert
  2. Selecting the datasets dynamically
  3. Applying conditions(Filters)
  4. Selecting fields(To be sent in the email)
  5. Preview(For Phase 1 we are doing only the table view)
  6. Selecting the recipient list from the data set
  7. Adding cc and Bcc fields
  8. Importing email ids from excel
  9. Creating the email service in the App builder backend
  10. Sending email on Manual trigger
  11. Layout styling(with header, footer and banner)

Description

Email Notification Model – The Mongoose schema file used to represent an Email Notification configuration follows the same principles as all other models used in the App Builder. It exposes a type representing the same object, and uses the permissions system as other models.

File index.ts in routes/notification - Provides REST endpoint for sending emails (Phase 1 - point 10); an email notification configuration is fetched from the database given a configuration ID, records are fetched according to user selected fields and filters, and are presented in a table with converted macros (e.g. {{today.now}}).Email is sent to the selected distribution list.

en.json - WHO copyright for sending emails

routes - upload/download – Fetch endpoints for importing email addresses from Excel, download for getting import template.

getFilter - added InTheLast case for dynamically calculating time offsets when filtering (e.g. new events in the last 24hr).

GraphQL Mutations - responsible for persisting email configurations and distribution lists.

Queries – responsible for fetching data for previews in notification configurations and distribution lists

Useful links

  • Please insert link to ticket - https://dev.azure.com/WHOHQ/EMSSAFE/_workitems/edit/16252
  • Please insert link to front-end pull request - https://github.com/ReliefApplications/ems-frontend/pull/2344

Type of change

  • [X] New feature (non-breaking change which adds functionality)
  • [X] This change requires a documentation update

SianaDicheva avatar Jan 29 '24 18:01 SianaDicheva

Hi @SianaDicheva,

I found a bug when using a resource with an array field, this part of the aggregation fails: { emailFields: { $filter: { input: "$matchingFields", as: "field", cond: { $regexMatch: { input: { $toString: "$$field.v", }, regex: {}, options: "i", }, }, }, }, } Error: PlanExecutor error during aggregation :: caused by :: Unsupported conversion from array to string in $convert with no onError value Reproduce: Create a resource with a multi-select dropdown, and try to create a notification with it.

MwanPygmay avatar Feb 14 '24 10:02 MwanPygmay

Hi @SianaDicheva,

I found a bug when using a resource with an array field, this part of the aggregation fails: { emailFields: { $filter: { input: "$matchingFields", as: "field", cond: { $regexMatch: { input: { toString:"$field.v", }, regex: {}, options: "i", }, }, }, }, } Error: PlanExecutor error during aggregation :: caused by :: Unsupported conversion from array to string in $convert with no onError value Reproduce: Create a resource with a multi-select dropdown, and try to create a notification with it.

Hi, thanks for pointing out this issue, we've debugged the problem and will push a fix soon :)

morgang-adappt avatar Feb 14 '24 11:02 morgang-adappt

Hi @SianaDicheva @morgang-adappt getting this error when trying to save/send email in the preview phase: { "errors": [ { "message": "Cannot query field "blockType" on type "DataSet".", "locations": [ { "line": 8, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } }, { "message": "Cannot query field "textStyle" on type "DataSet". Did you mean "tableStyle"?", "locations": [ { "line": 9, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } } ] }

MwanPygmay avatar Feb 23 '24 14:02 MwanPygmay

Hi @SianaDicheva @morgang-adappt getting this error when trying to save/send email in the preview phase: { "errors": [ { "message": "Cannot query field "blockType" on type "DataSet".", "locations": [ { "line": 8, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } }, { "message": "Cannot query field "textStyle" on type "DataSet". Did you mean "tableStyle"?", "locations": [ { "line": 9, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } } ] }

Hi @MwanPygmay ,

I have added a commit, which hopefully resolves these errors.

Let me know if there is anything else which pops up.

Have a lovely weekend!

SianaDicheva avatar Feb 23 '24 14:02 SianaDicheva

@HasnatL-Adapptlimited

closing this one as it's outdated

AntoineRelief avatar Apr 30 '24 06:04 AntoineRelief