Formatting plain-text notification comment (new lines stripped)

How to format/tweak plain-text notification comment?

From what I gathered, it's created based on `issue_digest_jabber.ftl` template and the comment section is created by `event.getPresentation()`. The problem is that new lines are being removed from comment making it completely garbled...

Is there a way to get documentation of `even` object or customise `event.getPresentation()` output in any way (maintain new lines)?

0
9 comments
Official comment

Hi. Some general information about configuring notification templates can be found here: Notification Templates. Please be informed that we plan to remove the Jabber integration completely in the coming release (2023.2), so I'm afraid we won't fix this issue even if it can be reproduced.

Stanislav Dubin I saw that page already but there is no mention of `event` object there so I have no idea how to extract comment from it. How to go about it? How, having `event` object in notification template, get comment element without new lines stripped?

 

Ad rem, I don't use jabber integration! I care about Plain Text notification, and from what I gathered it's obtained from jabber templates, hence me mentioning it.

If you have other suggestions how to adjust Plain Text email notification I'm all ears :-)

0

Can you please elaborate on the task you are facing here, how exactly you have tackled it so far, and what goes wrong in the process? We would appreciate it if you could provide a specific example here. For reference, issue_digest_email.ftl is used for email notifications. Other, more specific templates (that can be referenced indirectly) related to specific events can be viewed in the Template Components section of the Notification Templates page. Templates are based on the FreeMarker syntax.

0

I stated in first sentance: "How to format/tweak plain-text notification comment?"

"issue_digest_email.ftl" is used for email, but it's responsible for HTML emails. I want to format PLAIN TEXT emails.

From my investigatin those PLAIN TEXT email are generated from the "issue_digest_jabber.ftl" template, hence me mentioning it.

 

What I try to achieve is to have readable comment section in PLAIN TEXT email.

 

For example, if you comment in your issue something like this:

```

>> quote 1 lorem ipsum Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consequat 

> quote 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consequat 

My awesome comment

```

 

then in the plain text notification you get:
```

Comment: >> quote 1 lorem ipsum Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consequat > quote 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consequat My awesome comment
```

which I think you can agree, is quite awful to read and get the gist of it...

0

Please try the following expression:

        <#assign newCommentText  = event.newValue>
        <@markup>${newCommentText}</@markup><br>

If this fails to provide the necessary result, you can also try looking for places where the line breaks are supposed to be with FreeMarker and inserting <br/> there. The latter option depends on the possibility of HTML parsing on the end side, though, so this might not be a good fit here if you are looking to have zero HTML here.

0

The above resuts in `[error]`

The biggest issue is that there seems to be virtually no API docs about it at all which makes trying to adjust it walking in the dark..

No, https://www.jetbrains.com/help/youtrack/server/2021.4/Notification-Templates.html#notification-template-directives doesn't help here...

There is REST API, which has Event object (https://www.jetbrains.com/help/youtrack/devportal/api-entity-Event.html) but it seems different...

I tried

```

        <p>event: ${event}</p>

        <p>comment: ${event.comment}</p>
        <p>issue: ${issue}</p>
        <p>issue: ${issue.Comment}</p>

<br>
<br>
<br>

        <p>tmp: ${event.newValue}</p>

<br>

        <#assign newCommentText = event.newValue>
        <@markup>${newCommentText}</@markup><br>

```

 

Which resulted in:

```

event: jetbrains.youtrack.notifications.data.event.IssueCreatedEventAdapter@5b2b1ae7

comment: null

issue: jetbrains.youtrack.notifications.data.IssueEntitySnapshotAdapter@6f063e68

issue: null

 

tmp: null

[error]

```

 

a bit of WTF...

0

Are you using YT 2021.4? The method I suggested before may not work with this version as it may have been introduced later. You can try using the wiki markup instead, like so:

<#assign newCommentText = event.newValue>
<@wiki markdown=bcomment.usesMarkdown>${newCommentText}</@wiki><br>

However, from what I see, event.newValue returns null, so the issue is probably with the code itself. Can you share your current modified code?

0

Yes, event.newValue is null so there is error. I haven't modified the code at all as there is no reference so I have no clue what API is available.

 

From the sidebar I see:

LOCAL VARIABLE TYPE
from User
to User
issue Issue
change Change
reason Reason
only_via_duplicate boolean

 

This is basically the code (mostly default with some attempts at figuring out api):

```

<#list change.events as event>
    <#assign category = event.category>
    <#if category == "VOTERS">
        <#if event.getRemovedValues()?has_content>
            <#assign delta = "-1">
        <#else>
            <#assign delta = "+1">
        </#if>
        <p><@l10n>votes: ${delta} (${from.getVisibleName()}), total: ${issue.votes}</@l10n></p>
    <#elseif category == "COMMENT">
        <p>${event.getPresentation()}</p>
        <p>${Utils.getCommentUrl(event.comment)}</p>
    <#else>
        <p>${event.getPresentation()}</p>
    </#if>
    
    

        <p>event: ${event}</p>

        <p>comment: ${event.comment}</p>
        <p>issue: ${issue}</p>

        <#assign newCommentText  = event.newValue>
        <@markup>${newCommentText}</@markup><br>
    <@wiki markdown=bcomment.usesMarkdown>${newCommentText}</@wiki>


</#list>

```

 

It results in

```

event: jetbrains.youtrack.notifications.data.event.PropertyEventAdapter@6f93f037

comment: null

issue: jetbrains.youtrack.notifications.data.IssueEntitySnapshotAdapter@77b2f040
[error]
[error] 

````

 

One nitpick - "event.newValue" would be new value of the issue, and not the comment added?

0

event.newValue works in the latest versions (for showing the comment when this is the event that the user is notified of). May I ask what YouTrack version you are using and whether you considered an upgrade to the latest version? 

0

Please sign in to leave a comment.