Skip to content

Send multiple notifications by email#5875

Closed
armandfardeau wants to merge 67 commits intodecidim:developfrom
armandfardeau:feature/send-multiple-notifications-by-email
Closed

Send multiple notifications by email#5875
armandfardeau wants to merge 67 commits intodecidim:developfrom
armandfardeau:feature/send-multiple-notifications-by-email

Conversation

@armandfardeau
Copy link
Copy Markdown
Contributor

@armandfardeau armandfardeau commented Mar 19, 2020

🎩 What? Why?

Batch email notifications

Batch email notifications are a way to send several email notifications at the same time.

This is useful for grouping notifications and not overloading your users emails.

Notifications are sent in groups, sorted from the most recent notifications.

Notifications that have not been sent after a certain time are not sent at all. This means that your users have already received plenty of them and will already have to visit the platform.

Deleting a notification cancels the future associated email.

This is based on 3 parameters:

  • batch_email_notifications_enabled: Enable batch email notifications and disable single email notification (default to false)

  • batch_email_notifications_expired: period of time after which a notification is considered to have expired (default to 1 week)

  • batch_email_notifications_max_length: Number of notifications to send in the same email (default to 5)

How to setup?

App setup

In config/initialize/decidim.rb

Set to desired value

config.batch_email_notifications_enabled = true
config.batch_email_notifications_expired = 1.week
config.batch_email_notifications_max_length = 5

Server setup

Batch email notification required to execute a rake task ("rake decidim:batch_email_notifications:send") at regular intervals.

  1. Cron setup

    Use crontab -e and enter the following lines:

    0 */3 * * * cd {MY_APP} && {/path/to/bundle} exec rake decidim:batch_email_notifications:send

    You could find the documentation about cron on cron man page

  2. Heroku scheduler

    You can find information on how to setup heroku scheduler on heroku documentation

  3. Sidekiq scheduler

    In config/sidekiq.yml

    # sidekiq_scheduler.yml
    
    batch_email_notifications:
      every: ['3h', first_in: '1m']
      class: Decidim::BatchEmailNotificationsGeneratorJob
      queue: scheduled
      description: 'This job executes batch email notifications'

Many thanks to @Quentinchampenois for his help and co-authorship

📋 Subtasks

  • Add documentation regarding the feature
  • Add tests:
    • batch_email_notifications_generator_job
    • event_publisher_job
    • batch_notifications_mailer
    • batch_email_notifications_generator
    • notification
    • core
    • batch_email_notifications_tasks

📷 Screenshots (optional)

image

Demo

https://dcd-batch-notifications.osp.dev/

Sidekiq available connected as a system user at https://dcd-batch-notifications.osp.dev/sidekiq/
Letter opener available https://dcd-batch-notifications.osp.dev/letter_opener/

To test:

  • generate multiple notifications and mail, create proposals, debates, comments, etc...
  • Check mail in letter opener, you should have only "sent_now" priority ones.
  • Execute task "batch notification" in https://dcd-batch-notifications.osp.dev/sidekiq/recurring-jobs
  • Check mail in letter opener and check batch notification emails

@tramuntanal
Copy link
Copy Markdown
Contributor

I've labeled the task as WIP, please, feel free to remove the label when the PR is ready :D

@andreslucena andreslucena changed the title WIP: Feature/send multiple notifications by email Send multiple notifications by email May 18, 2020
@stale
Copy link
Copy Markdown

stale bot commented Jul 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. @carolromero & @andreslucena feel free to chime in.

@stale stale bot added the wontfix label Jul 18, 2020
@andreslucena
Copy link
Copy Markdown
Member

Hi @armandfardeau
Are you planning on doing this? For part of @decidim/product this is a very welcome and needed feature :D
For traceability, discussions on meta:

cc @virgile-dev

@stale stale bot removed the wontfix label Jul 20, 2020
@armandfardeau
Copy link
Copy Markdown
Contributor Author

Hi @andreslucena we are definitely planning to work on this, we will do a peer with @Quentinchampenois.

Please note that in the future version of this feature, multiple notifications per email will be the default setting and single-mode will be an option.

@andreslucena
Copy link
Copy Markdown
Member

Do you have an estimated time on when you'll find time for working on this again? Long-lived PRs are a maintenance nightmare (too many conflicts).

@Quentinchampenois
Copy link
Copy Markdown
Contributor

Do you have an estimated time on when you'll find time for working on this again? Long-lived PRs are a maintenance nightmare (too many conflicts).

Hi @andreslucena,

Sorry for the answer delay, I am planning on working on this PR this week

@Quentinchampenois
Copy link
Copy Markdown
Contributor

Quentinchampenois commented Aug 20, 2020

Hi,

I worked on this PR this week. I have added a priority feature to decide if a notification must be sent directly or can be delayed and send with other notifications.

Now, the question is, what is the priority to set for each notification ? By default, a notification with undefined priority will have a low priority.

What's left to finish this PR is to come up with a list for high priority notification (ex: forgot password, you don't want that to go in a batch). I'll be making a list of these in this comment, don't hesitate to comment back if you feel we missed some important ones.

High priority notifications ideas:

  • When administrator exports
  • A proposal has been moderated
  • A proposal has been reported
  • User forgot his / her password

@paulinebessoles
Copy link
Copy Markdown
Contributor

Good work @Quentinchampenois!

@carolromero and @andreslucena, what do you think about this list of high priority notifications (not going in a batch):

  • When administrator exports (decidim.export_mailer)
  • Welcome notification (decidim-core/app/events/decidim/welcome_notification_event.rb)
  • User forgot his / her password (devise.mailer.reset_password_instructions; devise.mailer.password_change)
  • User asked for an export of his data (decidim.export_mailer.data_portability_export)
  • User updated his profile (decidim-core/app/events/decidim/profile_updated_event.rb)
  • A content (proposal, meeting, comment, etc.) has been moderated
  • A content has been reported

Moreover, for Initiatives, I think there is a difference between mailer and events. How do you think we should deal with it?

@tramuntanal
Copy link
Copy Markdown
Contributor

I would say that all admin and platform notifications should have high priority, on the other side notifications coming from participant interactions could have low priority.
But let's see what @decidim/product has to say on this

@tramuntanal
Copy link
Copy Markdown
Contributor

Also, note that not all interactions that you mention would generate a notification. For example a "user forgot password" event simply generates an email, not a notification. I would leave this non notification emails out of scope.

@carolromero
Copy link
Copy Markdown
Member

Hi everyone,
We agree with @tramuntanal regarding the notifications for the admins, which should be of high priority.
We now differentiate the notifications of the own activity from the activity we follow, and most notifications are due to the latter:
imagen

So we think that the digest should contain the notifications related to the activity I follow. As a participant I probably want to receive a direct notification if someone mentions me or interacts with some content that I have created.

@armandfardeau
Copy link
Copy Markdown
Contributor Author

I would leave this non notification emails out of scope.

Yes that's the way we are doing it.

Quentinchampenois and others added 10 commits November 13, 2020 17:32
* increase batch notifications tasks specs

* add priority to EmailNotification and Notification generators job

* allow notification generator to receive priority

* add priority to events

* add priority to job notification generator for recipient

* add priority to email notification generator

* add priority to notification mailer

* add priority to email notification generator job

* update high_priority method in event publisher job

* add rule rubocop

* revert added specs in batch email notification
* Notification generators job harmonization

* light clean batch_email_notifications

* ensure notif are not sent for destroyed account

* light clean of specs

* fix redundant config in specs
@armandfardeau armandfardeau marked this pull request as ready for review November 19, 2020 11:45
@armandfardeau
Copy link
Copy Markdown
Contributor Author

Hello @tramuntanal It was a long trip but it's finished. You can find the test instructions in the issue description.

* fix css loading in emails

* update resource_text to safe_resource_text for event received template

* Revert "update resource_text to safe_resource_text for event received template"

This reverts commit a5ddf52.

* change notifications format in email batch notifications

* update translation and tests

* light refactor emails scss
@carolromero
Copy link
Copy Markdown
Member

Hi @armandfardeau I was going to review this but I get system errors when trying to access any participatory space. Would you please take a look at it? 🙏 Thanks

@armandfardeau
Copy link
Copy Markdown
Contributor Author

@carolromero Hi, thank you for doing this acceptance test. Could you reproduce the error so that we can intercept it?

@carolromero
Copy link
Copy Markdown
Member

@armandfardeau sure!

  1. Go to https://dcd-batch-notifications.osp.dev/processes
  2. Click on any process
  3. See the error

@armandfardeau
Copy link
Copy Markdown
Contributor Author

@armandfardeau sure!

  1. Go to https://dcd-batch-notifications.osp.dev/processes
  2. Click on any process
  3. See the error

Odd, I can't see anything on the monitoring.

@mrcasals
Copy link
Copy Markdown
Contributor

@armandfardeau I can see errors visiting this page:

https://dcd-batch-notifications.osp.dev/processes/nemo-aspernatur

@armandfardeau
Copy link
Copy Markdown
Contributor Author

@armandfardeau I can see errors visiting this page:

https://dcd-batch-notifications.osp.dev/processes/nemo-aspernatur

Thanks, we caught it via Sentry. I can't see the same errors as you.

@virgile-dev
Copy link
Copy Markdown
Contributor

Hey @armandfardeau @Quentinchampenois
With the help of Pauline, I did a little product do-over on the the email content itself.
Could you implement the changes 🙏 ?
notif-settings

@virgile-dev
Copy link
Copy Markdown
Contributor

Also we were discussing with @Quentinchampenois yesterday about the max notification that can fit in the email by default.
Instead of 5 we were thinking of 10 to leave a little room for users that receive a lot of notification (like admins).

@armandfardeau
Copy link
Copy Markdown
Contributor Author

Also we were discussing with @Quentinchampenois yesterday about the max notification that can fit in the email by default.
Instead of 5 we were thinking of 10 to leave a little room for users that receive a lot of notification (like admins).

Thanks for the feedback!

@mrcasals
Copy link
Copy Markdown
Contributor

mrcasals commented Feb 1, 2021

@armandfardeau is there any updates on this? I see some conflicts, check them out please! 😄

@armandfardeau
Copy link
Copy Markdown
Contributor Author

Hello everyone, we talked about this P.R. at OSP and we made the decision to close it because we can't work on it properly. We may reopen another one in the future.

@andreslucena andreslucena mentioned this pull request Nov 4, 2021
9 tasks
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.

9 participants