The notification system is a set of azure functions responsible for:
- Facilitating adding/removing moderators and subscribers
- Identifying changes in the database and sending alerts
There are two Azure Functions that update the email list.
- ModeratorEmail is a REST API that writes to the email list
- SenderEmail is a REST API that writes to the email list
- Email list is implemented using Azure Tables, using either "Moderator" or "Subscriber" as the partition key
Add email to subscribers list:
curl -X POST -d '{"email": "[email protected]"}' '<SubscriberEmailEndpoint>'
Delete email from subscribers list:
curl -X DELETE -d '{"email": "[email protected]"}' '<SubscriberEmailEndpoint>'
Add email to moderators list:
curl -X POST -d '{"email": "[email protected]"}' '<ModeratorEmailEndpoint>'
Delete email from moderators list:
curl -X DELETE -d '{"email": "[email protected]"}' '<ModeratorEmailEndpoint>'
There are three other Azure Functions that make up the email notification system.
In the moderators flow:
- A change in the Cosmos DB metadata store triggers the SendModeratorEmail function
- If there is a newly detected orca call that requires a moderator to validate, the function fetches the relevant email list
- The function then calls SendGrid to send emails to moderators
In the subscribers flow:
- A change in the Cosmos DB metadata store triggers the DbToQueue function
- If there is a new orca call that the moderator has validated, the function sends a message to a queue
- The SendSubscriberEmail function periodically checks the queue
- If there are items in the queue, the function fetches the relevant email list
- The function then calls SendGrid to send emails to subscribers
There are two Azure Functions that query the email list.
- ListModeratorEmails is a REST API that lists all saved moderator emails
- ListSubscriberEmails is a REST API that lists all saved subscriber emails
List all subscriber emails:
curl -X GET '<SubscriberEmailEndpoint>'
List all moderator emails:
curl -X GET '<ModeratorEmailEndpoint>'
- Access to the Orca Conservancy Azure subscription
- Install the .NET Core 3.1 SDK
- Azure Function Tools
- If using Visual Studio, include "Azure development" workload in installation
- If using Visual Studio Code, add the "Azure Functions" extension
- If using CLI, install the Azure Functions Core Tools
- If running locally - Azure storage emulator
To build the functions locally:
- Go to /NotificationSystem directory (if not already)
- If building from the command line, run
dotnet build NotificationSystem.csproj
- If building from visual studio, simply open .csproj and build as normal
All resources are located in resource group LiveSRKWNotificationSystem.
- Storage account with queues, email template images and moderator/subscriber list: orcanotificationstorage
- Metadata store (from which some functions are triggered): aifororcasmetadatastore
- Azure function app: orcanotification
- SendGrid account (for sending emails): aifororcas
It is recommended to go to the "orcanotification" function app, then Settings > Configuration to find the app settings used.
Create local.settings.json in the current directory (NotificationSystem) using the below template. Fill in with valid configuration strings.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"OrcaNotificationStorageSetting": "<storage account connection string>",
"aifororcasmetadatastore_DOCUMENTDB": "<cosmos db connection string>",
"SendGridKey": "<SendGrid API key>",
"SenderEmail": "<email address>"
}
}
- Go to the "orcanotification" function app (link 3 above).
- On the "Overview" tab, make sure the status of the function shows running.
- On the "Functions" tab, you should see all the functions of the notification system. Enable/Disable as needed.