Full Comment in AEM asset annotation email

Commenting on assets, available via a timeline, allows users to create a centralized and historical record for discussions about the asset. Comments are just text-based messages, but they have the helpful feature of mentioning other AEM users. At this point, the said user is notified of the comment via their inbox.

Annotations allow comments to be associated with specific areas of an asset, assuming that the asset can have an image representation to which the annotation can be applied to. When annotating an asset, arrows or circles are drawn, identifying a portion of the asset along with a descriptive comment, making it clear exactly what the comment is refers to. And, like comments, annotations also support mentions of AEM users, which are delivered to the user’s inbox.

When you mention a user in an asset annotation, by default they will receive an email with content such as:- you are mentioned in a comment which does not contain the actual comment. We will have to customize this default behavior to include full comments in the email.

By default, the email looks something like this.

AEM Assets

How it works

The email template resides at  “/libs/settings/workflow/notification/email/tasks/created/en.txt”.

But if you want to add the actual comment in this email, it is not a straightforward process such as adding the comment in the email template ${item. comment}. Because the email template takes values from the task node and the task node does not contain the actual comment. To add the comment in the email we will have to add the comment to the task node. First, let’s see how the data flows and the services that are called in the process.

Data Flow Process 

Below are a few pointers regarding the functionality:

AEM Asset
  1. com.day.cq.dam.core.impl.event.CommentNotificationSender.java creates the task at [2]
  2. com.day.cq.workflow.impl.email.TaskEMailNotificationService.java reads the task/event and triggers the mail using the template
  3. The legacy root for the email templates was /etc/workflow/[1].
  4. The email templates are loaded at the bundle load/start, so any changes in the template will only be picked and used post-restart of the bundle [3].
  5. In this case, the comments are saved under <Asset path>/jcr:content/comments as nodes and not pushed to the task node at [/var/taskmanagement/tasks] for each comment. I do not see an option to add them to the mail template.

[1] /libs/settings/workflow/notification/email/tasks/created/en.txt

[2] Day Communique 5 Workflow Implementation(com.day.cq.workflow.cq-workflow-impl)

You can check these bundles in your quickstart jar, and get more ideas of how these services work.

Solution 
  1. Create a custom EventListner similar to CommentEventListener, inside it call your custom CommentNotificationSender class.
  2. Inside CustomCommentNotificationSender class update the create task method by adding one more parameter for the actual comment and adding it to your description of your task node, you can also create a new property for the comment and add the same to your email template2
AEM Asset

3. Make sure to call the createTask method with the message as an argument in the sendNotification() method.

AEM Asset

4. In Your custom eventlistner call the sendNotification method with the required arguments.

AEM Asset

Conclusion  

Make sure to disable the OOTB CommentEventListener class to avoid receiving duplicate emails. To disable the component you can use the ACS Commons component disabler. 

Add this configuration to your codebase, and it will disable your OOTB listener com.adobe.acs.commons.util.impl.ComponentDisabler.cfg.json

 

AEM Asset

Finally, you will receive an email with full comments as in the below image.

AEM asset