Giter Club home page Giter Club logo

notificationservice's Introduction

NotificationService

ABP version NuGet NuGet Download Discord online GitHub stars

An integrated user notification service Abp module, supporting email, SMS, PM, and more other methods.

Installation

  1. 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
  2. Add DependsOn(typeof(NotificationServiceXxxModule)) attribute to configure the module dependencies. (see how)

  3. Add builder.ConfigureNotificationService(); to the OnModelCreating() method in MyProjectMigrationsDbContext.cs.

  4. Add EF Core migrations and update your database. See: ABP document.

Usage

You can create a notification using a notification factory or manually.

Create with Notification Factory

  1. 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(CurrentTenant.Id, userIds, text, new Dictionary<string, object>());
        }
    }
  2. Use the factory to create a notification and publish it.

    var eto = await userWelcomeNotificationFactory.CreateAsync(
        model: new UserWelcomeNotificationDataModel(userData.UserName, giftCardCode),
        userId: userData.Id
    );
    
    // use the distributed event bus to create notifications and send them in the background
    await distributedEventBus.PublishAsync(eto);
    // or use the integration service to create notifications and send them in the background
    var notifications = await notificationIntegrationService.CreateAsync(eto);
    // or use the integration service to create notifications and send it them immediately
    var notifications = await notificationIntegrationService.QuickSendAsync(eto);

Create Manually

Publish the notification.

await distributedEventBus.PublishAsync(
    new CreateEmailNotificationEto(CurrentTenant.Id, userIds, subject, body));

Notifications

Providers

Q&A

How to Change User's Email Address and Phone Number Info Source

You can override the IdentityUserEmailAddressProvider and the IdentityUserPhoneNumberProvider.

How to Use a Dynamic Notification Content Template

You can use the ABP Text Templating feature, see the demo.

Road map

  • Private messaging notification provider.
  • WeChat official template message notification provider.
  • WeChat mini-program subscribe message notification provider.
  • Notification management UI.

notificationservice's People

Contributors

gdlcf88 avatar indexlang avatar slarkerino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

notificationservice's Issues

Appears when subscribing after publishing an event:System.FormatException: Could not deserialize JSON text

I installed in the Domain project EasyAbp.NotificationService.Domain and EasyAbp.NotificationService.Provider.Mailing packages, and introduced in DomainModule module:
image
The code follows the source code example to write the test:
image
However, the console did report the following error and did not execute the subscription event:
image
Detailed error message:

---> (Inner Exception #4) System.FormatException: Could not deserialize JSON text: '{"$type":"EasyAbp.NotificationService.Provider.Mailing.CreateEmailNotificationEto, EasyAbp.NotificationService.Provider.Mailing.Abstractions","Subject":"test","Body":"","TenantId":null,"UserIds":{"$type":"System.Collections.Generic.List1[[System.Guid, System.Private.CoreLib]], System.Private.CoreLib","$values":["1a5d39c8-2822-42e0-a92e-39fae1a6a4ab"]}}'
---> Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type EasyAbp.NotificationService.Provider.Mailing.CreateEmailNotificationEto. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'Subject', line 1, position 152.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Rebus.Serialization.Json.JsonSerializer.Deserialize(String bodyString, Type type)
--- End of inner exception stack trace ---
at Rebus.Serialization.Json.JsonSerializer.Deserialize(String bodyString, Type type)
at Rebus.Serialization.Json.JsonSerializer.GetMessage(TransportMessage transportMessage, Encoding bodyEncoding)
at Rebus.Serialization.Json.JsonSerializer.Deserialize(TransportMessage transportMessage)
at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage)
at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func1 next)
at Rebus.Retry.FailFast.FailFastStep.Process(IncomingStepContext context, Func1 next) at Rebus.Retry.Simple.SimpleRetryStrategyStep.DispatchWithTrackerIdentifier(Func1 next, String identifierToTrackMessageBy, ITransactionContext transactionContext, String messageId, String secondLevelMessageId)<---
`

Add error messages when using SMS for testing:

---> (Inner Exception #4) System.FormatException: Could not deserialize JSON text: '{"$type":"EasyAbp.NotificationService.Provider.Sms.CreateSmsNotificationEto, EasyAbp.NotificationService.Provider.Sms.Abstractions","Text":"test","Properties":{"$type":"System.Collections.Generic.Dictionary2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib","MyProperty":"123456"},"TenantId":null,"UserIds":{"$type":"System.Collections.Generic.List1[[System.Guid, System.Private.CoreLib]], System.Private.CoreLib","$values":["1a5d39c8-2822-42e0-a92e-39fae1a6a4ab"]}}' ---> Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type EasyAbp.NotificationService.Provider.Sms.CreateSmsNotificationEto. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'Text', line 1, position 139. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Rebus.Serialization.Json.JsonSerializer.Deserialize(String bodyString, Type type) --- End of inner exception stack trace --- at Rebus.Serialization.Json.JsonSerializer.Deserialize(String bodyString, Type type) at Rebus.Serialization.Json.JsonSerializer.GetMessage(TransportMessage transportMessage, Encoding bodyEncoding) at Rebus.Serialization.Json.JsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func1 next)
at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func1 next) at Rebus.Retry.FailFast.FailFastStep.Process(IncomingStepContext context, Func1 next)
at Rebus.Retry.Simple.SimpleRetryStrategyStep.DispatchWithTrackerIdentifier(Func1 next, String identifierToTrackMessageBy, ITransactionContext transactionContext, String messageId, String secondLevelMessageId)<---

升级到abp7 与发行版后报错

Autofac.Core.DependencyResolutionException: An exception was thrown while activating Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionEndpointDataSourceFactory -> Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider -> λ:Microsoft.AspNetCore.Mvc.Abstractions.IActionDescriptorProvider[] -> Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider -> Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory -> λ:Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider[] -> Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider -> Microsoft.Extensions.Options.UnnamedOptionsManager1[[Microsoft.AspNetCore.Mvc.MvcOptions, Microsoft.AspNetCore.Mvc.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] -> Microsoft.Extensions.Options.OptionsFactory1[[Microsoft.AspNetCore.Mvc.MvcOptions, Microsoft.AspNetCore.Mvc.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] -> λ:Microsoft.Extensions.Options.IConfigureOptions1[[Microsoft.AspNetCore.Mvc.MvcOptions, Microsoft.AspNetCore.Mvc.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]][] -> Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcOptionsSetup -> Volo.Abp.Localization.AbpStringLocalizerFactory. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.Extensions.Localization.ResourceManagerStringLocalizerFactory, Microsoft.Extensions.Options.IOptions1[Volo.Abp.Localization.AbpLocalizationOptions], System.IServiceProvider, Volo.Abp.Localization.External.IExternalLocalizationStore)' on type 'AbpStringLocalizerFactory'.
---> System.MissingMethodException: Method not found: 'Volo.Abp.Localization.LocalizationResource Volo.Abp.Localization.LocalizationResourceExtensions.AddBaseTypes(Volo.Abp.Localization.LocalizationResource, System.Type[])'.
at EasyAbp.NotificationService.NotificationServiceDomainSharedModule.<>c.b__0_1(AbpLocalizationOptions options)
at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at Microsoft.Extensions.Options.UnnamedOptionsManager1.get_Value()
at Volo.Abp.Localization.AbpStringLocalizerFactory..ctor(ResourceManagerStringLocalizerFactory innerFactory, IOptions1 abpLocalizationOptions, IServiceProvider serviceProvider, IExternalLocalizationStore externalLocalizationStore) at lambda_method862(Closure, Object[]) at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate() --- End of inner exception stack trace --- at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate() at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass12_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext ctxt, Action1 next)
at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt)
at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action1 next)
at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext context, Action1 next)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt)
at Autofac.Core.Resolving.Middleware.SharingMiddleware.<>c__DisplayClass5_0.b__0()
at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid id, Func1 creator) at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid primaryId, Nullable1 qualifyingId, Func1 creator) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt)
at Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt)
at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt)
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request)
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request)
at Autofac.Core.Container.ResolveComponent(ResolveRequest request)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters)
at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints) at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens) at Volo.Abp.AspNetCore.Mvc.AbpAspNetCoreMvcModule.<>c.<ConfigureServices>b__1_10(EndpointRouteBuilderContext endpointContext) at Microsoft.AspNetCore.Builder.AbpAspNetCoreApplicationBuilderExtensions.<>c__DisplayClass0_0.<UseConfiguredEndpoints>b__0(IEndpointRouteBuilder endpoints) at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action1 configure)
at Microsoft.AspNetCore.Builder.AbpAspNetCoreApplicationBuilderExtensions.UseConfiguredEndpoints(IApplicationBuilder app, Action`1 additionalConfigurationAction)
at Evo.Scm.ScmHttpApiHostModule.OnApplicationInitialization(ApplicationInitializationContext context) in /Users/choby/Documents/zhixuan/evo-scm-backend/src/Evo.Scm.HttpApi.Host/ScmHttpApiHostModule.cs:line 281
at Volo.Abp.Modularity.AbpModule.OnApplicationInitializationAsync(ApplicationInitializationContext context)
at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.InitializeAsync(ApplicationInitializationContext context, IAbpModule module)

经过检查代码发现是这段代码出错

Configure(options =>
{
options.Resources
.Add("en")
.AddBaseTypes(typeof(AbpValidationResource))
.AddVirtualJson("/EasyAbp/NotificationService/Localization");
});

trust https in Web.Host project

I cannot run this project
dotnet watch run --project host/EasyAbp.NotificationService.Web.Host/ -r linux-x64
in linux
this is error

` An unhandled exception occurred while processing the request.
AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)

HttpRequestException: The SSL connection could not be established, see inner exception.
System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)

AbpRemoteCallException: An error occurred during the ABP remote HTTP request. (The SSL connection could not be established, see inner exception.) See the inner exception for details.
Volo.Abp.Http.Client.ClientProxying.ClientProxyBase.RequestAsync(ClientProxyRequestContext requestContext)`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.