Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notifications feature to provide a way notify the user #12638

Merged
merged 26 commits into from
Dec 29, 2022

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Oct 14, 2022

Fix #12651

Notifications (OrchardCore.Notifications)

The Notifications module provides the infrastructure necessary to send notification to the app users. Happy module number 200! 🥳 🔥

Notification Methods

There are many methods to send notifications to a user (e.x., Web, Email, Push, SMS, etc.). In addition to web notification, OrchardCore is shipped with Email based notifications. To allow users to receive Email notification, enable the Email Notifications feature. Note, you must also configure the SMTP Settings. When multiple notification methods are enabled, the user can opt-in or opt-out any method he/she wish to receive by editing their profile.

Adding Custom Notification Provider

To add a new notification method like Push or SMS, you can simple implement the INotificationMethodProvider interface and then register it as we do in OrchardCore.Notifications.Email feature

[Feature("OrchardCore.Notifications.Email")]
public class EmailNotificationStartup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<INotificationMethodProvider, EmailNotificationProvider>();
    }
}

How to send a notification

You can send notification to a user via code by injecting INotificationManager then calling the SendAsync(...) method. Alternatively, you can use workflows to notify a user about an event that took place.

Workflow Activities

When OrchardCore.Workflows feature is enabled, you'll see new activites that would allow you to notify users using workflows. Here are some of the available workflow activities

  • Notify Content's Owner Task
  • Notify User Task

Remaining items

  • Add some sort of caching to notifications to prevent having to query the notification on each page load.

Ideas for future releases

  • Add real time communication with the client by using SignalR and implement SentAsync(NotificationContext context) handler to notify the client.
  • Add notification digest so a user can set how often to receive notifications (other than web notification.)
  • Add background worker to allow the admin to auto remove old notifications

@Skrypt
Copy link
Contributor

Skrypt commented Oct 14, 2022

Just a quick thought here. A notification is generally something that will display on the UI. Here, sending an email after an event has been triggered is something that can be done with Workflows. Need to review and see what is the difference in this PR.

Please when you get time add an issue with an explanation of what it is going to add or fix in OC.

@MikeAlhayek
Copy link
Member Author

MikeAlhayek commented Oct 14, 2022

@Skrypt yes I will add an issue at some point. I’ll also demo this at some point. But to address your concerns, a notification to me can come from anything (like Email, Web, Push, SMS...). An email is just a method of notification. I am planning to also add Web notification as an implementation of the notification infrastructure. Currently, I added workflow activities that allow you to sent the user notifications based on their preferences. The key difference here is that a user can opt-out of notification or opt-in a specific notification. For example, Gitter allows you to get web and/or email notifications. Similar concept here a notification can be sent yo a user based on their preferences.

Here is an example from the UI how a user can set which method of notification to receive. The “Push Notification” you see below is an implementation I have in one of my app. The Push notification won't be part of this PR, but will be easy add for anyone that want it "based on their provider"

image

The notification is really driven from workflows, but can easily be triggered from code INotificationManager as well.

@MikeAlhayek MikeAlhayek marked this pull request as ready for review October 15, 2022 23:52
@MikeAlhayek
Copy link
Member Author

@Skrypt
Check out the new changes. I added a Web implementation in addition to the web notifications. I am planning to demo this in Tuesday if time permits.

@hishamco
Copy link
Member

Before I look into the code, I suggest to have this module with a web notifications integrated with the UI as GitHub already have, we might add email notification as workflow if we do so

If this done, I need to close an issue that I filed long time ago in Orchard Core Contrib, to do the same exact thing

@MikeAlhayek
Copy link
Member Author

MikeAlhayek commented Oct 16, 2022

@hishamco the web implementation already has a simple UI to list all notifications. Still it can use some more enhancements "maybe for later time".

Here is some nice to have functions that were not yet added

  1. Filter to show "unread", "read" or "all notification"
  2. Action button to delete all notification or delete selected notification.
  3. Search bar to search notifications
  4. Probably add a configurable background worker that would delete old read notification on regular bases. The admin would specify how often to run this job using cron timer.

I am not sure I want to add the above 3 steps in v1 but we'll think about it.

Also, email notifications is already implemented :) I am planning to demo this on Tuesday so if you want to see it in action, feel free to join the meeting or watch the recording.

@hishamco
Copy link
Member

Waiting for your demo

@MikeAlhayek
Copy link
Member Author

cc/ @Piedone here is the PR for notifications

@Piedone
Copy link
Member

Piedone commented Oct 18, 2022

Thanks!

…ication is the only implementation. Content Item was added to notification but the UI isn't aware of that URL yet.
@MikeAlhayek
Copy link
Member Author

MikeAlhayek commented Oct 20, 2022

@ns8482e as you requested the notifications does not depend on user. It now depends on object. Let me know your thought about the code here please

@ns8482e
Copy link
Contributor

ns8482e commented Oct 23, 2022

@MikeAlhayek Lot of files, need some time to digest ;)

@MikeAlhayek
Copy link
Member Author

@ns8482e yes lots of things in this. It's best to fork it and try it out locally

@MikeAlhayek MikeAlhayek added this to the 1.6 milestone Dec 5, 2022
@MikeAlhayek
Copy link
Member Author

@sebastienros made some final feedback you had around notification. Maybe it's time to merge it to get more feedback from users?

@MikeAlhayek MikeAlhayek merged commit eefbfdb into OrchardCMS:main Dec 29, 2022
@ricocsharp
Copy link

@MikeAlhayek How can I use this module in a 1.5 OC project?

@hishamco
Copy link
Member

hishamco commented Feb 2, 2023

@ricocsharp try to use the nightly builds from Cloudsmith feed

@MikeAlhayek
Copy link
Member Author

Since this is going to be in 1.6, and you are using 1.5, you can try installing the latest preview into your web project and see if it'll be discoverable by the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a feature to send notifications to the user
7 participants