An integrated user notification service Abp module, supporting email, SMS, PM, and more other methods.
We have launched an online demo for this module: https://notification.samples.easyabp.io
-
Install the following NuGet packages. (see how)
- EasyAbp.NotificationService.Application
- EasyAbp.NotificationService.Application.Contracts
- EasyAbp.NotificationService.Domain
- EasyAbp.NotificationService.Domain.Shared
- EasyAbp.NotificationService.EntityFrameworkCore
- EasyAbp.NotificationService.HttpApi
- EasyAbp.NotificationService.HttpApi.Client
- (Optional) EasyAbp.NotificationService.MongoDB
- (Optional) EasyAbp.NotificationService.Web
- (Optional) EasyAbp.NotificationService.Provider.Mailing
- (Optional) EasyAbp.NotificationService.Provider.Sms
-
Add
DependsOn(typeof(NotificationServiceXxxModule))
attribute to configure the module dependencies. (see how) -
Add
builder.ConfigureNotificationService();
to theOnModelCreating()
method in MyProjectMigrationsDbContext.cs. -
Add EF Core migrations and update your database. See: ABP document.
You can create a notification using a notification factory or manually.
-
Create a factory.
public class UserWelcomeNotificationFactory : NotificationFactory<UserWelcomeNotificationDataModel, CreateSmsNotificationEto>, ITransientDependency { public override async Task<CreateSmsNotificationEto> CreateAsync( UserWelcomeNotificationDataModel model, IEnumerable<Guid> userIds) { var text = $"Hello, {model.UserName}, here is a gift card code for you: {model.GiftCardCode}"; return new CreateSmsNotificationEto(userIds, text, new Dictionary<string, object>()); } }
-
Use the factory to create a notification and publish it.
var eto = await userWelcomeNotificationFactory.CreateAsync( model: new UserWelcomeNotificationDataModel(userData.UserName, giftCardCode), userId: userData.Id ); await distributedEventBus.PublishAsync(eto);
Publish the notification.
await distributedEventBus.PublishAsync(new CreateEmailNotificationEto(userIds, subject, body));
You can override the IdentityUserEmailAddressProvider and the IdentityUserPhoneNumberProvider.
You can use the ABP Text Templating feature, see the demo.
- Private messaging notification provider.
- WeChat uniform message notification provider.
- Notification management UI.