Softeq.NetKit.NotificationService is a RESTful microservice that allows to quickly bring notification support to a developing solution. Service supports the following notification types:
- Push via Azure Notification Hub
- Email via SendGrid
- SMS via Twilio
API is written in Asp.Net Core 2.0 and secured with OAuth2 protocol.
Swashbuckle is enabled to provide API consumers with the documentation.
API has an integration with [Softeq.NetKit.EventDriverCommunication] (https://github.com/Softeq/EventDrivenCommunication) to enable sending notification requests via Message Bus.
Service exposes the following APIs:
/settingsAPI to initialize new user settings, read and manage;/notificationsAPI to send new notifications;/notifications/historyAPI to view and delete notification history assoicated to a particular user;/notifications/push/subscriptionAPI to subscribe or unsubscribe user's mobile devices to receive Push notifications;
-
Configure Data Storage: The microservice supports multiple storages: SQL - implemented in
Softeq.NetKit.Notifications.Store.SqlNoSQL via Azure CosmosDB - implemented inSofteq.NetKit.Notifications.Store.CosmosDBWhen desired data storage is chosen,
- Add a reference to a data store implementation to
Softeq.NetKit.Notifications.Webproject - Add Automapper configuration to Startup.cs
services.AddAutoMapper(typeof(Service.ContainerModule).Assembly, typeof(Store.Sql.ContainerModule).Assembly);
- Register Autofac module in DI container
builder.RegisterModule(new Store.Sql.ContainerModule());
- Add a reference to a data store implementation to
-
Update
appsettings.jsonby configuring storage connection strings, API keys
- Add new event to
Softeq.NetKit.Notifications.Domain.Models.Notification.NotificationEventenum
public enum NotificationEvent
{
MyNewCustomEvent = 0
}- Modify
Softeq.NetKit.Notifications.Service.NotificationSenders.NotificationEventConfigurationby specifying what notification type will support newly-added event
public static Dictionary<NotificationType, IList<NotificationEventConfiguration>> Config = new Dictionary<NotificationType, IList<NotificationEventConfiguration>>
{
{
NotificationType.Email, new List<NotificationEventConfiguration>
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent, true)
}
},
{
NotificationType.SMS, new List<NotificationEventConfiguration>
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent)
}
},
{
NotificationType.Push, new List<NotificationEventConfiguration>
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent)
}
}
};-
Implement Notification message per supported notification type under
/NotificationSenders/NOTIFICATION_TYPE/Messages- For Push notification
public class MyNewCustomEventPushMessage : PushNotificationMessage { [JsonProperty("someId")] public Guid SomeId { get; set; } public MyNewCustomEventPushMessage() { NotificationType = (int)NotificationEvent.MyNewCustomEvent; BodyLocalizationKey = "MyNewCustomEvent_body"; TitleLocalizationKey = "MyNewCustomEvent_title"; } }
- For Email notification
public class MyNewCustomEventEmailModel : IEmailTemplateModel { public Guid SomeId { get; set; } } public class MyNewCustomEventEmailMessage : BaseEmailNotification<MyNewCustomEventEmailModel> { public MyNewCustomEventEmailMessage(string toEmail, string toName, MyNewCustomEventEmailModel model) : base(new RecipientDto(toEmail, toName)) { TemplateModel = model; } }
- For Sms notification
public class MyNewCustomEventSmsModel : ISmsNotification { public string CustomField { get; set; } } public class MyNewCustomEventSmsMessage : BaseSmsNotification { public MyNewCustomEventSmsMessage() { } }
-
Implement Validator per supported Notificationn Type under
/NotificationSenders/NOTIFICATION_TYPE/Validators- For Email notification
internal class MyNewCustomEventEmailMessageValidator : BaseEmailValidator<MyNewCustomEventEmailMessage> { public MyNewCustomEventEmailMessageValidator() { RuleFor(x => x.TemplateModel.SomeId).NotEqual(Guid.Empty); } }
- For Push notification
internal class MyNewCustomEventPushMessageValidator : BasePushMessageValidator<MyNewCustomEventPushMessage> { public MyNewCustomEventPushMessageValidator() { RuleFor(x => x.SomeId).NotEqual(Guid.Empty); } }
- For Sms notification
internal class MyNewCustomEventSmsMessageValidator : BaseSmsValidator<MyNewCustomEventSmsMessage> { public MyNewCustomEventSmsMessageValidator() { RuleFor(x => x.CustomField).NotEqual(string.Empty()); } }
-
Update MessageFactory under
/NotificationSenders/NOTIFICATION_TYPE/***MessageFactory.cs -
Add localization info under
/NotificationSenders/NOTIFICATION_TYPE/Resources
This project is maintained by Softeq Development Corp.
We specialize in .NET core applications.
We welcome any contributions.
The Query Utils project is available for free use, as described by the LICENSE (MIT).