Template-based notification engine Currently supports e-mail notifications.
List of third-party libraries:
-
DotLiquid is a templating system. How to use liquid markeup.
-
SQL Server used as a data storage
-
Redis used as a message broker
-
Serilog is a library for logging.
Wolf.Notification is an ASP.NET WebAPI application that provides an API for creating and sending messages.
The API has the following settings:
-
NotificationDbContextis a connection string to SQL Server -
Redisis a connection string to a Redis message broker. -
Loggingis a default ASP.NET MVC section
Example:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"NotificationDbContext": "Server=localhost;Initial Catalog=notification_v1;Persist Security Info=False;User ID=sa;Password=MP3cxJ6ptB3R93VP;Connection Timeout=30;",
"Redis": "localhost"
}
}
Wolf.Notification.EmailSender is a console application that listens for an Runner:QueueChannelName queue and sends e-mail messages.
The application has the following settings:
-
Loggingis a default .Net Core section -
Serilogis a configuration for the Serilog librar. See Formatting Output -
NotifApiproperties to connect to Wolf.Notification API -
Runner:QueueConnectionStringis a connection string to a Redis message broker. -
Runner:QueueChannelNameis a channel that the application will listen to and wait for the message. -
Smtpis a SMTP server configuration.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
}
}
]
},
"NotifApi": {
"BaseUrl": "http://localhost:5380",
"UserAgentName": "EmailSender",
"AuthOptions": {
"StsUrl": "https://devid.myaccount.com",
"ClientId": "notif_sender",
"ClientSecret": "HIDDEN",
"Scope": "notif_api"
}
},
"Runner": {
"QueueConnectionString": "localhost",
"QueueChannelName": "email"
},
"Smtp": {
"Server": "smtp.gmail.com",
"Port": 587,
"Username": "2386612@gmail.com",
"Password": "1234",
"FromEmail": "2386612@gmail.com"
}
}
-
If not using docker, install Redis Server. There are many ports for windows. Here is one of them: https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100
-
You need to execute
src/Wolf.Notification/Sqlscripts before build and deployin the applications. Thesrc/Wolf.Notification/Sqlcontains the following scripts:
-
src/Wolf.Notification/Sql/000_init_db.sql- create a new database (if you already have a database, you can skip this script) -
src/Wolf.Notification/Sql/001_[audit]_audit_schema.sql- create an audit schema (if you do not want to have audit tables, you can skip this script) -
src/Wolf.Notification/Sql/002_template.sql(MANDATORY) -
src/Wolf.Notification/Sql/003_[audit]_template.sqlis a script to create an audit table for thetemplatetable. (Optional) -
src/Wolf.Notification/Sql/004_template_default_recipient.sql(MANDATORY) -
src/Wolf.Notification/Sql/005_[audit]_template_default_recipient.sqlis a script to create an audit table for thetemplate_default_recipienttable. (Optional) -
src/Wolf.Notification/Sql/006_message.sql(MANDATORY) -
src/Wolf.Notification/Sql/007_[audit]_message.sqlis a script to create an audit table for themessagetable. (Optional) -
src/Wolf.Notification/Sql/008_recipient.sql(MANDATORY) -
src/Wolf.Notification/Sql/009_[audit]_recipient.sqlis a script to create an audit table for therecipienttable. (Optional)
- You need to create an template using
POST /template. See swagger
See example,
{
"name": "list of services",
"subject": "Notification for {{username}}",
"body": "<b>Hello {{username}},</b> We have the following applications:<ul>{% for app in apps %}<li>{{app.name}} with ID = {{app.ID}}</li>{% endfor %}</ul>"
}
-
You need to run the Wolf.Notification.EmailSender application
-
You can send message using
POST /message/send/template/{templateId}. Provider parameter must beemail
See example,
{
"tokenValues": {
"username": "Greg",
"apps": [
{
"name": "Wolf Forms",
"ID": 111
},
{
"name": "Wolf Flows",
"ID": 222
},
{
"name": "Wolf Notifications",
"ID": 333
},
]
},
"recipients": [
"gzinger@zbitinc.com"
]
}
!!! Before using, you need to do the following steps:
-
Setup Database Scripts
-
Change
ConnectionStrings__NotificationDbContextto your -
Change
Smtp__Username,Smtp__Password,Smtp__FromEmailto your settings
docker-compose build
docker-compose up