An integrated user notification service Abp module, supporting email, SMS, PM, and more other methods.
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.PrivateMessaging
- (Optional) EasyAbp.NotificationService.Provider.Sms
- (Optional) EasyAbp.NotificationService.Provider.WeChatOfficial
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.
publicclassUserWelcomeNotificationFactory:NotificationFactory<UserWelcomeNotificationDataModel,CreateSmsNotificationEto>,ITransientDependency{publicoverrideasyncTask<CreateSmsNotificationEto>CreateAsync(UserWelcomeNotificationDataModelmodel,IEnumerable<Guid>userIds){vartext=$"Hello, {model.UserName}, here is a gift card code for you: {model.GiftCardCode}";returnnewCreateSmsNotificationEto(CurrentTenant.Id,userIds,text,newDictionary<string,object>());}}
Use the factory to create a notification and publish it.
vareto=awaituserWelcomeNotificationFactory.CreateAsync(model:newUserWelcomeNotificationDataModel(userData.UserName,giftCardCode),userId:userData.Id);// use the distributed event bus to create notifications and send them in the backgroundawaitdistributedEventBus.PublishAsync(eto);// or use the integration service to create notifications and send them in the backgroundvarnotifications=awaitnotificationIntegrationService.CreateAsync(eto);// or use the integration service to create notifications and send it them immediatelyvarnotifications=awaitnotificationIntegrationService.QuickSendAsync(eto);
Publish the notification.
awaitdistributedEventBus.PublishAsync(newCreateEmailNotificationEto(CurrentTenant.Id,userIds,subject,body));- Mailing
- PrivateMessaging
- Sms
- WeChatOfficial
You can override the IdentityUserEmailAddressProvider and the IdentityUserPhoneNumberProvider.
You can use the ABP Text Templating feature, see the demo.
- Private messaging notification provider.
- WeChat official template message notification provider.
- WeChat mini-program subscribe message notification provider.
- Notification management UI.
