{"id":7316,"date":"2014-07-31T05:55:46","date_gmt":"2014-07-31T12:55:46","guid":{"rendered":"http:\/\/localhost\/exoblog\/?p=7316"},"modified":"2023-06-05T16:49:24","modified_gmt":"2023-06-05T14:49:24","slug":"extend-social-email-notifications","status":"publish","type":"post","link":"https:\/\/www.exoplatform.com\/blog\/extend-social-email-notifications\/","title":{"rendered":"Tutorial: how to extend social email notifications"},"content":{"rendered":"<p>The email notification feature will help you to avoid missing things that happen in your organization. These emails will help you to keep track of activities and events in your social intranet.<\/p>\n<p>There are two types of email notification: notification emails for each event and a digest email that collects all notifications during a certain period and is sent once per day or per week.<\/p>\n<p>By default, eXo Platform supports a large of number of events like: new user, connection request, space invitation, space join request, mention, comment on activity, like on activity, post on my stream and post in my spaces.<\/p>\n<p>In some cases, <b>you might want to add other notifications or customize existing notifications<\/b> based on a dedicated event. In this tutorial, you will see how to add a new notification, <b>\u2018One of my connections has posted a message<\/b>\u2019, by implementing your own eXo social notification plugin.<\/p>\n<p><!--more--><\/p>\n<h2>Sample Notification Extension<\/h2>\n<p>This extension will send an email notification when a connection posts an activity on their activity stream.<\/p>\n<p>This new notification should also appear in the settings. Just like the others, users can choose whether they want to receive this kind of notification or not.<\/p>\n<h3>Prerequisites<\/h3>\n<ul>\n<li>The extension requires Platform 4.1.x. I\u2019ve already tested it on Platform 4.1-M1 and 4.1-M2.<\/li>\n<li>This tutorial involves developing your own extension, so it is good if you understand <a href=\"https:\/\/docs.exoplatform.org\/\" target=\"_blank\" rel=\"noopener\">eXo Platform Extensions<\/a>.<\/li>\n<\/ul>\n<h3>Creating your extension project<\/h3>\n<p>Creating your extension called <span class=\"navCode\">custom-notification-extension<\/span> requires two packages:<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/2014\/07\/01-package-details.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-7318\" src=\"\/blog\/wp-content\/uploads\/2014\/07\/01-package-details.png\" alt=\"01-package-details\" width=\"300\" srcset=\"https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details.png 370w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-191x300.png 191w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-301x473.png 301w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-209x328.png 209w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-150x236.png 150w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-83x131.png 83w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-57x90.png 57w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/01-package-details-19x30.png 19w\" sizes=\"(max-width: 370px) 100vw, 370px\" \/><\/a><\/p>\n<p><span class=\"navCode\">custom-notification-config.jar<\/span> is where you declare the extension webapp as a dependency of the portal container. This means that under <span class=\"navCode\">custom-notification-extension.jar<\/span> you need to create <span class=\"navCode\">\/conf\/configuration.xml<\/span> with the following content:<\/p>\n<pre class=\"lang:default decode:true \">&lt;object-param&gt;\n\t&lt;name&gt;addDependencies&lt;\/name&gt;\n\t&lt;object type=\"org.exoplatform.container.definition.PortalContainerDefinitionChange$AddDependencies\"&gt;\n &lt;!-- The name of the portal container --&gt;\n\t\t&lt;field name=\"dependencies\"&gt;\n\t\t\t&lt;collection type=\"java.util.ArrayList\"&gt;\n\t\t\t\t&lt;value&gt;\n\t\t\t\t\t&lt;string&gt;custom-notification-extension&lt;\/string&gt;\n\t\t\t\t&lt;\/value&gt;\n\t\t\t&lt;\/collection&gt;\n\t\t&lt;\/field&gt;\n\t&lt;\/object&gt;\n&lt;\/object-param&gt;<\/pre>\n<p><span class=\"navCode\">custom-notification-extension.war<\/span> contains resources and configurations. The webapps are loaded in the order defined in the list of dependencies in the <span class=\"navCode\">PortalContainerDefinition<\/span>.<\/p>\n<p>In <span class=\"navCode\">\/conf\/configuration.xml<\/span> you need to register two <i>external component plugins<\/i>:<\/p>\n<pre class=\"lang:default decode:true \">&lt;external-component-plugins&gt;\n\t&lt;target-component&gt;org.exoplatform.social.core.manager.ActivityManager&lt;\/target-component&gt;\n\t&lt;component-plugin&gt;\n\t\t&lt;name&gt;ActivityNotificationImpl&lt;\/name&gt;\n\t\t&lt;set-method&gt;addActivityEventListener&lt;\/set-method&gt;\n\t\t&lt;type&gt;org.exoplatform.custom.notification.impl.ActivityNotificationImpl&lt;\/type&gt;\n\t&lt;\/component-plugin&gt;\n&lt;\/external-component-plugins&gt;<\/pre>\n<p>* When an activity is created (this event is <span class=\"navCode\">addActivityEventListener<\/span>) then <span class=\"navCode\">org.exoplatform.custom.notification.impl.ActivityNotificationImpl<\/span> will be triggered. In this class, we will implement sending an email notification (see the details in the next section):<\/p>\n<pre class=\"lang:default decode:true \">&lt;external-component-plugins&gt;\n\t&lt;target-component&gt;org.exoplatform.commons.api.notification.service.setting.PluginContainer&lt;\/target-component&gt;\n\t&lt;component-plugin&gt;\n\t\t&lt;name&gt;notification.plugins&lt;\/name&gt;\n\t\t&lt;set-method&gt;add&lt;\/set-method&gt;\n\t\t&lt;type&gt;org.exoplatform.custom.notification.plugin.ActivityConnectionPlugin&lt;\/type&gt;\n\t\t&lt;description&gt;Initial information for plugin.&lt;\/description&gt;\n\t\t&lt;init-params&gt;\n\t\t\t&lt;object-param&gt;\n\t\t\t\t&lt;name&gt;template.ActivityConnectionPlugin&lt;\/name&gt;\n\t\t\t\t&lt;description&gt;The template of ActivityConnectionPlugin&lt;\/description&gt;\n\t\t\t\t&lt;object type=\"org.exoplatform.commons.api.notification.plugin.config.PluginConfig\"&gt;\n\t\t\t\t\t&lt;field name=\"pluginId\"&gt;\n\t\t\t\t\t\t&lt;string&gt;ActivityConnectionPlugin&lt;\/string&gt;\n\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t&lt;field name=\"resourceBundleKey\"&gt;\n\t\t\t\t\t\t&lt;string&gt;UINotification.label.ActivityConnectionPlugin&lt;\/string&gt;\n\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t&lt;field name=\"order\"&gt;\n\t\t\t\t\t\t&lt;string&gt;5&lt;\/string&gt;\n\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t&lt;field name=\"defaultConfig\"&gt;\n\t\t\t\t\t\t&lt;collection type=\"java.util.ArrayList\"&gt;\n\t\t\t\t\t\t\t&lt;value&gt;&lt;string&gt;Instantly&lt;\/string&gt;&lt;\/value&gt;\n\t\t\t\t\t\t\t&lt;!--value&gt;&lt;string&gt;Daily&lt;\/string&gt;&lt;\/value\u2192\n\t\t\t\t\t\t\t&lt;!--value&gt;&lt;string&gt;Weekly&lt;\/string&gt;&lt;\/value--&gt;\n\t\t\t\t\t\t&lt;\/collection&gt;\n\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t&lt;field name=\"groupId\"&gt;\n\t\t\t\t\t\t&lt;string&gt;connections&lt;\/string&gt;\n\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t&lt;field name=\"templateConfig\"&gt;\n\t\t\t\t\t\t&lt;object type=\"org.exoplatform.commons.api.notification.plugin.config.TemplateConfig\"&gt;\n\t\t\t\t\t\t\t&lt;field name=\"bundlePath\"&gt;\n\t\t\t\t\t\t\t\t&lt;string&gt;locale.notification.template.Notification&lt;\/string&gt;\n\t\t\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t\t\t&lt;field name=\"templatePath\"&gt;\n\t\t\t\t\t\t\t\t&lt;string&gt;war:\/notification\/templates\/ActivityConnectionPlugin.gtmpl&lt;\/string&gt;\n\t\t\t\t\t\t\t&lt;\/field&gt;\n\t\t\t\t\t\t&lt;\/object&gt;\n        \t\t\t&lt;\/field&gt;\n\t\t\t\t&lt;\/object&gt;\n\t\t\t&lt;\/object-param&gt;\n\t\t&lt;\/init-params&gt;\n\t&lt;\/component-plugin&gt;\n&lt;\/external-component-plugins&gt;<\/pre>\n<p>* This configuration will register a plugin called <span class=\"navCode\">ActivityConnectionPlugin<\/span> with some important parameters:<\/p>\n<ul>\n<li>defaultConfig: <i>Instantly<\/i> \u2013 sends email notifications right away;<i> daily <\/i>and<i> weekly <\/i>are used for digest emails.<\/li>\n<li>groupId: <i>general, connections, spaces, activity<\/i> \u2013 This is the group for your custom notification in Notification Settings (you could also create a new group).<\/li>\n<li>templateConfig: <i>bundlePath<\/i> \u2013 points to the resource bundle file and <i>templatePath <\/i>is the template for the email notification\u2019s content.<\/li>\n<\/ul>\n<h3>Implementing your own eXo social notification plugin<\/h3>\n<p><span class=\"navCode\">ActivityNotificationImpl.java<\/span> is extended from <span class=\"navCode\">ActivityListenerPlugin.java<\/span>. In this class we override the <i>saveActivity<\/i> method:<\/p>\n<pre class=\"lang:default decode:true \">public void saveActivity(ActivityLifeCycleEvent event) {\n\tExoSocialActivity activity = event.getSource();    \n\tNotificationContext ctx = NotificationContextImpl.cloneInstance().append(ACTIVITY, activity);\n\n\tctx.getNotificationExecutor().with(ctx.makeCommand(NotificationKey.key(ActivityConnectionPlugin.ID)))\n                                 .execute(ctx);\n}<\/pre>\n<p>The main class you need to implement is <span class=\"navCode\">ActivityConnectionPlugin<\/span>. This is extended from <a href=\"https:\/\/github.com\/exodev\/\" target=\"_blank\" rel=\"noopener\"><i>AbstractNotificationPlugin<\/i><\/a><i> <\/i>with some important methods:<\/p>\n<ul>\n<li><i>1. <\/i><i>makeNotification<\/i> creates a <i>NotificationInfo<\/i> object, which is used to build a message for sending a notification instantly and store it in the database for building a digest message.<\/li>\n<li><i>2. <\/i><i>makeMessage<\/i> makes the <i>MessageInfo<\/i> from the given <i>NotificationInfo<\/i> that is kept inside <i>NotificationContext<\/i>, which is sent immediately when a user is active.<\/li>\n<li><i>3. <\/i><i>makeDigest<\/i> makes the digest message from the given <i>NotificationInfo<\/i> that is kept inside NotificationContext.<\/li>\n<li><i>4. <\/i><i>isValid<\/i> validates the conditions for sending an email notification. If it returns <i>false<\/i> then a message is not sent.<br \/>\nFor this example, we make sure that if a poster posts on their activity stream then an email is sent. If they post on somebody else\u2019s activity stream or in a space, then an email is not sent.<\/li>\n<\/ul>\n<p><b>* Edit email content<\/b><\/p>\n<p><span class=\"navCode\">custom-notification-extension\/webapp\/WEB-INF\/notification\/template\/ActivityConnectionPlugin.gtmpl<\/span><\/p>\n<p>* <b>Edit resource bundle<\/b><\/p>\n<p><span class=\"navCode\">custom-notification-extension\/resources\/locale\/notification\/template\/Notification_en.properties<\/span><\/p>\n<p>If you want to add more languages, simply clone this file and change _en to a required language, then create a translation for it.<\/p>\n<p>You can download the source code <a href=\"https:\/\/github.com\/exo-addons\/resource-center\/tree\/master\/sample-notification-extension\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Deployment<\/p>\n<p>* Build a project using: <span class=\"navCode\">mvn clean install<\/span><\/p>\n<p>* Copy the <span class=\"navCode\">custom-notification-extension.war<\/span> file to the <span class=\"navCode\">${PLF_TOMCAT}\/webapps<\/span> directory.<\/p>\n<p>* Copy the <span class=\"navCode\">custom-notification-config-xxx.jar<\/span> file to the <span class=\"navCode\">${PLF_TOMCAT}\/lib directory<\/span>.<\/p>\n<p>* Start your tomcat using: <span class=\"navCode\">.\/start_eXo.sh<\/span><\/p>\n<p>Now in your Notification Settings you should see the new notification \u2018One of my connections has posted a message\u2019 under Connections.<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-7319\" src=\"\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings.png\" alt=\"02-notifications-settings\" width=\"300\" height=\"138\" srcset=\"https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings.png 974w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-300x139.png 300w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-768x355.png 768w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-720x333.png 720w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-500x231.png 500w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-360x166.png 360w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-200x92.png 200w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-100x46.png 100w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/02-notifications-settings-65x30.png 65w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Test it to see whether you receive an email notification when one of your connections posts an activity on their activity stream. You should receive an email like this:<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/2014\/07\/03-notification.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-7320\" src=\"\/blog\/wp-content\/uploads\/2014\/07\/03-notification.png\" alt=\"03-notification\" width=\"300\" height=\"163\" srcset=\"https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification.png 604w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-300x164.png 300w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-500x273.png 500w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-360x197.png 360w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-200x109.png 200w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-100x55.png 100w, https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/07\/03-notification-55x30.png 55w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Congratulations on your first simple customized social email notification! Now you can implement any customizations you might need.<\/p>\n<h2>Going further<\/h2>\n<p>Of course, customizations can do more than this sample customized social notification. You can register any event to send email notifications, like user login, logout, posting to the wiki, uploading or creating documents, calendar events, tasks\u2026<\/p>\n<p>Just do it. If you have any questions, don\u2019t hesitate to post them on the <a href=\"https:\/\/community.exoplatform.com\/portal\/intranet\/forum\" target=\"_blank\" rel=\"noopener\">Support Forums<\/a>.<\/p>\n<h2>References<\/h2>\n<p>+ Email Notification Specification: <a href=\"https:\/\/community.exoplatform.com\/portal\/login?initialURI=%2Fportal%2Fintranet%2Fnotes\" target=\"_blank\" rel=\"noopener\">https:\/\/community.exoplatform.com\/portal\/intranet\/wiki\/<\/a><\/p>\n<p>+ Managing Email Notifications: <a href=\"https:\/\/docs.exoplatform.org\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.exoplatform.org<\/a><\/p>\n<p>+ Creating your Extension Project: <a href=\"https:\/\/docs-old.exoplatform.org\/public\/index.jsp?topic=%2FPLF40%2FPLFDevGuide.eXoPlatformExtensions.CreatingExtensionProject.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs-old.exoplatform.org\/public\/index.jsp?topic=%2FPLF40%2FPLFDevGuide.eXoPlatformExtensions.CreatingExtensionProject.html<\/a><\/p>\n<p><b><a href=\"https:\/\/community.exoplatform.com\/portal\/dw\/\" target=\"_blank\" rel=\"noopener\">Join the eXo tribe<\/a> by registering for the community and get updates, tutorials, support, and access to the Platform and add-on downloads!<\/b><\/p>\n<p><!--begin adv-events--><\/p>\n<div class=\"adv-events\" style=\"background: #476fad; padding: 30px 20px; color: white; border-radius: 3px;\">\n<div class=\"media\">\n<div class=\"pull-right\"><a href=\"#\"><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-6587 alignright\" src=\"https:\/\/www.exoplatform.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-make-the-most-of-eXo-platform41.png\" alt=\"make-the-most-out-of-eXo-platform4\" width=\"161\" height=\"85\"><br \/>\n<\/a><\/div>\n<div class=\"media-body\">\n<h4 class=\"media-heading\">Make the most out of eXo Platform 4<\/h4>\n<p>Register to the next webinar and get a complete overview of what you can do with eXo Platform 4. <strong><a href=\"https:\/\/www.exoplatform.com\/contact-us\/?utm_source=BlogEn&amp;utm_medium=Blog&amp;utm_campaign=Content&amp;utm_content=link\">Reserve your seat now!<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end adv-events--><\/p>\n","protected":false},"excerpt":{"rendered":"The email notification feature will help you to avoid missing things that happen in your organization. These emails will help you to keep track of activities and events in your social intranet. There are two types of email notification: notification emails for each event and a digest email that collects all notifications during a certain [&hellip;]","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[699],"tags":[],"lang":"en","translations":{"en":7316},"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/posts\/7316"}],"collection":[{"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/comments?post=7316"}],"version-history":[{"count":0,"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/posts\/7316\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/media?parent=7316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/categories?post=7316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.exoplatform.com\/blog\/wp-json\/wp\/v2\/tags?post=7316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}