https://github.com/softeq/netkit.notification
https://github.com/softeq/netkit.notification
dotnet dotnetcore microservice netkit notification
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/softeq/netkit.notification
- Owner: Softeq
- License: mit
- Created: 2019-01-11T13:01:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T04:29:17.000Z (over 3 years ago)
- Last Synced: 2025-01-27T14:53:44.850Z (about 1 year ago)
- Topics: dotnet, dotnetcore, microservice, netkit, notification
- Language: C#
- Size: 144 KB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Softeq.NetKit.NotificationService
Softeq.NetKit.NotificationService is a RESTful microservice that allows to quickly bring notification support to a developing solution.
Service supports the following notification types:
1. Push via Azure Notification Hub
2. Email via SendGrid
3. 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.
# Getting Started
## Explore
Service exposes the following APIs:
1. ```/settings``` API to initialize new user settings, read and manage;
2. ```/notifications``` API to send new notifications;
3. ```/notifications/history``` API to view and delete notification history assoicated to a particular user;
4. ```/notifications/push/subscription``` API to subscribe or unsubscribe user's mobile devices to receive Push notifications;
## Configure
1. Configure Data Storage:
The microservice supports multiple storages:
SQL - implemented in ```Softeq.NetKit.Notifications.Store.Sql```
NoSQL via Azure CosmosDB - implemented in ```Softeq.NetKit.Notifications.Store.CosmosDB```
When desired data storage is chosen,
* Add a reference to a data store implementation to ```Softeq.NetKit.Notifications.Web``` project
* Add Automapper configuration to Startup.cs
```csharp
services.AddAutoMapper(typeof(Service.ContainerModule).Assembly,
typeof(Store.Sql.ContainerModule).Assembly);
```
* Register Autofac module in DI container
```csharp
builder.RegisterModule(new Store.Sql.ContainerModule());
```
2. Update ```appsettings.json``` by configuring storage connection strings, API keys
## Develop
1. Add new event to ```Softeq.NetKit.Notifications.Domain.Models.Notification.NotificationEvent``` enum
```csharp
public enum NotificationEvent
{
MyNewCustomEvent = 0
}
```
2. Modify ```Softeq.NetKit.Notifications.Service.NotificationSenders.NotificationEventConfiguration``` by specifying what notification type will support newly-added event
```csharp
public static Dictionary> Config = new Dictionary>
{
{
NotificationType.Email, new List
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent, true)
}
},
{
NotificationType.SMS, new List
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent)
}
},
{
NotificationType.Push, new List
{
new NotificationEventConfiguration(NotificationEvent.MyNewCustomEvent)
}
}
};
```
3. Implement Notification message per supported notification type under ```/NotificationSenders/NOTIFICATION_TYPE/Messages```
* For Push notification
```csharp
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
```csharp
public class MyNewCustomEventEmailModel : IEmailTemplateModel
{
public Guid SomeId { get; set; }
}
public class MyNewCustomEventEmailMessage : BaseEmailNotification
{
public MyNewCustomEventEmailMessage(string toEmail, string toName, MyNewCustomEventEmailModel model) : base(new RecipientDto(toEmail, toName))
{
TemplateModel = model;
}
}
```
* For Sms notification
```csharp
public class MyNewCustomEventSmsModel : ISmsNotification
{
public string CustomField { get; set; }
}
public class MyNewCustomEventSmsMessage : BaseSmsNotification
{
public MyNewCustomEventSmsMessage()
{
}
}
```
3. Implement Validator per supported Notificationn Type under ```/NotificationSenders/NOTIFICATION_TYPE/Validators```
* For Email notification
```csharp
internal class MyNewCustomEventEmailMessageValidator : BaseEmailValidator
{
public MyNewCustomEventEmailMessageValidator()
{
RuleFor(x => x.TemplateModel.SomeId).NotEqual(Guid.Empty);
}
}
```
* For Push notification
```csharp
internal class MyNewCustomEventPushMessageValidator : BasePushMessageValidator
{
public MyNewCustomEventPushMessageValidator()
{
RuleFor(x => x.SomeId).NotEqual(Guid.Empty);
}
}
```
* For Sms notification
```csharp
internal class MyNewCustomEventSmsMessageValidator : BaseSmsValidator
{
public MyNewCustomEventSmsMessageValidator()
{
RuleFor(x => x.CustomField).NotEqual(string.Empty());
}
}
```
4. Update MessageFactory under ```/NotificationSenders/NOTIFICATION_TYPE/***MessageFactory.cs```
5. Add localization info under ```/NotificationSenders/NOTIFICATION_TYPE/Resources```
## About
This project is maintained by Softeq Development Corp.
We specialize in .NET core applications.
## Contributing
We welcome any contributions.
## License
The Query Utils project is available for free use, as described by the [LICENSE](/LICENSE) (MIT).