Notification BeforeCreate event not firing

Hi,

I am building a solution that needs to do something whenever a notification is sent in the community and thought the best way to handle this would be on the notification before create event handler.  As such I have created a very simple plugin as follows;

namespace NotifcationEventHandler
{
    public class NotificationHandler : IPlugin
    {
        public string Name => "Event Handler Test";

        public string Description => "Tests and handles event notifications";

        public void Initialize()
        {
            Apis.Get<INotifications>().Events.BeforeCreate += new NotificationBeforeCreateEventHandler(Notification_Before_Create);
        }

        private void Notification_Before_Create(NotificationBeforeCreateEventArgs e)
        {
            //Here we will send a notication

            string s = e.ContentUrl;
        }
    }
}

Clearly the event doesn't actually do anything (for simplicity), but if I place a breakpoint within the handler I get different results, for example,

  1. Sending a private message between two users when I have two different browsers open and both users logged in - the breakpoint is hit
  2. If one of the browsers is closed and the user in the first browser sends a message, the breakpoint is not hit - I did consider that this could be because the responsibility would then fall to the job service, however, the plugin is also installed there and debugging that confirms that the breakpoint is not hit

Is anyone able to advise what I could be doing wrong here?  Ultimately I am looking to capture whenever any notification is sent.

We are testing with 12.0.3.17950, but have the same problem with previous versions of 12.

Any help is, as always, greatly appreciated.

Thanks,

James.



Added version information.
[edited by: James Phillips at 9:26 AM (GMT 0) on Fri, Oct 22 2021]
Parents
  • Hi James,

    Are you wanting to capture all instances of every notification created - for instance, sending notification to all subscribers about a new blog post - or just for private messages? 

    For private messages (aka conversations), check the Conversation Messages In-Process API Service for those events.

    For notifications, you will want to hande the BeforeUpdate event as well. Notifications are dynamic and can be updated based on similar events occuring (for instance, "UserA commented on this blog post" to "UserA and UserB commented on this blog post"). Likely in your instance, you are seeing a case of the conversation message notification being updated, because a previous message was sent recently.

Reply
  • Hi James,

    Are you wanting to capture all instances of every notification created - for instance, sending notification to all subscribers about a new blog post - or just for private messages? 

    For private messages (aka conversations), check the Conversation Messages In-Process API Service for those events.

    For notifications, you will want to hande the BeforeUpdate event as well. Notifications are dynamic and can be updated based on similar events occuring (for instance, "UserA commented on this blog post" to "UserA and UserB commented on this blog post"). Likely in your instance, you are seeing a case of the conversation message notification being updated, because a previous message was sent recently.

Children