Skip to content

Latest commit

 

History

History

NotificationSystem

AI For Orcas - Notification System

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

Architecture

Update email list

add email architecture

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

Sample REST calls

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>'

Send email to moderators and subscribers

send email architecture

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 AWS Simple Email Service 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 AWS Simple Email Service to send emails to subscribers

Get email list

list email architecture

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

Sample REST calls

List all subscriber emails:

curl -X GET '<SubscriberEmailEndpoint>'

List all moderator emails:

curl -X GET '<ModeratorEmailEndpoint>'

Prerequisites

  • 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

Build

To build the functions locally:

  1. Go to /NotificationSystem directory (if not already)
  2. If building from the command line, run
    dotnet build NotificationSystem.csproj
    
  3. If building from visual studio, simply open .csproj and build as normal

Azure Resource Dependencies

All resources are located in resource group LiveSRKWNotificationSystem.

  1. Storage account with queues, email template images and moderator/subscriber list: orcanotificationstorage
  2. Metadata store (from which some functions are triggered): aifororcasmetadatastore
  3. Azure function app: orcanotification

Run Locally

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>",
        "AWS_ACCESS_KEY_ID": "<AWS Access Key>",
        "AWS_SECRET_ACCESS_KEY": "<AWS Secret Key>",
        "SenderEmail": "<email address>"
    }
}

Run on Azure

  1. Go to the "orcanotification" function app (link 3 above).
  2. On the "Overview" tab, make sure the status of the function shows running.
  3. On the "Functions" tab, you should see all the functions of the notification system. Enable/Disable as needed.