Skip to Content Skip to Menu

email notifications

  • AlanJones
  • AlanJones
  • ONLINE
  • Posts: 512
  • Thanks: 43
  • Karma: 2
10 hours 44 minutes ago #340502 by AlanJones
email notifications was created by AlanJones
So some time ago you suggested I setup an autoaction to send notifications as emails.
I set up the following in User:
if ( ! $variables->getPublished() ) {
    return [];
}
return $variables->getRecipients();

And the trigger is:  activity_OnAfterNotificationEntityStore

It worked ok for a long while but has become increasingly sporadic, sometimes sending mails, sometimes not, sometimes sending to the group, sometimes to everyone registered...
Any ideas to make this work a bit better - the external notification thing (email, push) is just an essential for my clients. I know you're working on something.

Own Your Own Community!

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48891
  • Thanks: 8358
  • Karma: 1450
10 hours 22 minutes ago - 10 hours 22 minutes ago #340505 by krileon
Replied by krileon on topic email notifications
It's only going to send a notification if CB Activity would log a notification. So there are times where it's not going to send such as duplicate notifications or notifications to people that aren't set to receive that notification. That is the only way to extend CB Activity notification behavior. I've nothing more to suggest right now beyond just making emails for specific triggers (e.g. onAfterUserRegistration, onAfterJoinGroup, etc..). The trigger is defined as follows.
Code:
$_PLUGINS->trigger( 'activity_onAfterNotificationEntityStore', [ $this, &$notification, $new ] );

It's possible you may need to check for var3 being true or 1 in your auto action conditions. This ensures it only sends an email for newly created notifications. That maybe where the sporadic behavior is coming from as it could be sending during edits. getRecipients() basically just returns a list of user ids that the notification was logged to in the _comprofiler_plugin_activity_notification database table and that's it. So if a user doesn't get your email then they never not the notification to begin with.

We won't have a universal notification system until sometime in CB 3.x. It'll be your standard notification you might of seen on other sites with the name of the notification then checkboxes for email, private message, sms, on-site, etc..


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 10 hours 22 minutes ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48891
  • Thanks: 8358
  • Karma: 1450
10 hours 18 minutes ago #340506 by krileon
Replied by krileon on topic email notifications
Looks like the only usecase where that trigger won't fire is if the recipients of an existing notification are being updated, but the notification itself is not updating. Will review adding a activity_onAfterNotificationEntityUpdate trigger, but you're likely to get duplicate email notifications doing that. I'll try to add to the trigger a $newRecipients variable by diffing the before and after of the added recipients to alleviate that.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48891
  • Thanks: 8358
  • Karma: 1450
9 hours 50 minutes ago #340507 by krileon
Replied by krileon on topic email notifications
Ok, this is now available in latest CB Activity build release. It's now possible to act on an existing notification getting new recipients. This behavior is common with grouped notifications like profile.%.login notifications for example. Below is the usage I'd recommend.

Global
Triggers: activity_onAfterNotificationEntityStore, activity_onAfterNotificationEntityUpdate
Type: Email
User: Code
Access: Everybody
User
Code:
if ( ! $variables['var2']->getPublished() ) { return; } if ( $variables['var3'] === false ) { return; } if ( $variables['var3'] === true ) { return $variables['var2']->getRecipients(); } if ( is_array( $variables['var3'] ) ) { return $variables['var3']; }

The rest of your auto action should be able to remain the same. Added some logic for var3 since for Store it's going to be TRUE for a new notification otherwise FALSE if the notification itself was modified. For Update var3 will always be a recipient diff so you'll only send emails for new recipients.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: AlanJones

Please Log in or Create an account to join the conversation.

  • AlanJones
  • AlanJones
  • ONLINE
  • Posts: 512
  • Thanks: 43
  • Karma: 2
5 hours 36 minutes ago #340510 by AlanJones
Replied by AlanJones on topic email notifications
Thank you - trying it out right now... I'll let you know how it goes, so far so good :)
 

Own Your Own Community!
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum