Email notifications for time approval
The purpose of this feature is to demonstrate how applications can send email notification to selected people on certain events.
Scenario:
In WLMDP application, TimeEntries tab, users can select time entries and submit them for management approval. Once these items are successfully submitted, the respective manager(s) receive an email notification stating that there are new times available in CRSD platform that requires their attention.
The email contains a link to the CRSD website and the name of the submitter.
Common component Notification Publisher:
We utilized Notification Publisher for sending the emails.
Steps for setting up the feature:
Create your account at https://notification.canada.ca/
Create a new service
Note: A service can be a Live Service (it doesn't have a limit to send e-mail, use this as a production one) or Trial ServiceCreate a new template
Note: Once you create your template, it's important to save your template ID. You will use that in the body when you call this serviceGive access to your team members.
Note: On a trial service, it's important to add your client in a safelist if they are not part of your team member listCreate your API Key
Note: As a standard, it will be important to save this api key in Azure KeyVault. You will use that in the body when you call this service
Note2: In test, create your key as Team and safelist
Good To Know
To test with Postman:
On Premise
POST https://wwwappstest.tc.gc.ca/Saf-Sec-Sur/2/NotificationPublisher/Notification
SCED
POST https://ncdnotificationpublisherapp01.azurewebsites.net/Notification
Header:
Body:
{
"EmailAddress": "your-email-address",
"TemplateId": "your template GUID from GCNotify",
"Reference": "",
"Personalisation": { "user": "your-name" , "utilisateur": "your-name"},
"ApiKey": "your gcnotify key"
}
NOTES:
You can find an example of TemplateID and API Key here:
To test locally, you need to add values in your secrets.json
To find the info, please take a look on the pipeline library:
DEV > https://dev.azure.com/transport-canada/MAACE-Solution and Data Architecture Services/_library?itemType=VariableGroups&view=VariableGroupView&variableGroupId=255&path=NotificationPublisher-DEV
Send Notification API in WLMDP:
A good practice is to always separate responsibilities in SDLC.
There is a service class has been implemented in WLMDP named NotificationApiService that contains a function named SendNotificationEmail. This function needs one parameter RequestEmailModel as follows:
public class RequestEmailModel
{
public string EmailAddress { get; set; } // recipient email address
public string TemplateId { get; set; } // templateId obtained from GCNotify account (explained in previous steps)
public string Reference { get; set; } = "";
public Dictionary<string, dynamic> Personalisation { get; set; } // name and value of any custom field in the template
public string ApiKey { get; set; } // Api key obtained from GCNotify
}