N
Novu13mo ago
gigo1980

If I use topic subscription, is there a group selector in the digest?

Hi I am using topic subscription, Is it possible inside the digest to get a "groupBy" topic for the email Template? Criteria should be to see only the related Message to the subscriberID
12 Replies
Pawan Jain
Pawan Jain13mo ago
Hi @gigo1980 Digest depends on workflow + subsciberId + custom digest key (if any). Since topic is just group of subscribers. When you trigger a workflow to a topic, internally it is triggered to all subscribers of topic. groupBy helper is used to group payload events by key name
gigo1980
gigo1980OP13mo ago
What will be then here the right groupBy, If I would group by "from"?
Hallo {{subscriber.firstName}}

{{#if step.digest}}
du hast {{step.total_count}} neue Nachrichten.

{{#each step.events}}
<li>{{this.from}}: {{this.message}}</li>
{{/each}}
{{/if}}
Hallo {{subscriber.firstName}}

{{#if step.digest}}
du hast {{step.total_count}} neue Nachrichten.

{{#each step.events}}
<li>{{this.from}}: {{this.message}}</li>
{{/each}}
{{/if}}
Pawan Jain
Pawan Jain13mo ago
if your payload is like this Event 1
{
"from": "Pawan",
"age": "30"
}
{
"from": "Pawan",
"age": "30"
}
Event 2
{
"from": "Pawan",
"age": "32"
}
{
"from": "Pawan",
"age": "32"
}
Event 3
{
"from": "Jain",
"age": "31"
}
{
"from": "Jain",
"age": "31"
}
then this email template
Hallo {{subscriber.firstName}}

{{#if step.digest}}
du hast {{step.total_count}} neue Nachrichten.

{{#each (groupBy step.events "from") }}
<h3>from: {{key}}<h3>
{{#each items}}
<li>{{age}}</li>
{{/each}}
{{/each}}
{{/if}}
Hallo {{subscriber.firstName}}

{{#if step.digest}}
du hast {{step.total_count}} neue Nachrichten.

{{#each (groupBy step.events "from") }}
<h3>from: {{key}}<h3>
{{#each items}}
<li>{{age}}</li>
{{/each}}
{{/each}}
{{/if}}
will give you this result
Pawan Jain
Pawan Jain13mo ago
No description
Pawan Jain
Pawan Jain13mo ago
in this line Hallo Pawan du hast 3 neue Nachrichten. Pawan is picked from subscriber.firstName @gigo1980 let me know if I am able to explain correctly
gigo1980
gigo1980OP13mo ago
Ok great that works so far, is there also an way to aggreagate something like in linked in. So that I can see the persons on my side, people how have written something, next birthdays and so on. Can I do this in one Workflow or does I need for each "kind" and seperare workflow and nees something like an aggregation workflow?
No description
gigo1980
gigo1980OP13mo ago
Is there something like arrayLength? Or is there a way to contribute custom handlebar functions to you project? {{arrayLength yourArray}}
Handlebars.registerHelper('arrayLength', function(array) {
return array.length;
});
Handlebars.registerHelper('arrayLength', function(array) {
return array.length;
});
gigo1980
gigo1980OP13mo ago
GitHub
novu/packages/application-generic/src/usecases/compile-template/com...
🔥 The open-source notification infrastructure with fully functional embedded notification center 🚀🚀🚀 - novuhq/novu
Novu_Bot
Novu_Bot13mo ago
@gigo1980, you just advanced to level 2!
Pawan Jain
Pawan Jain13mo ago
@gigo1980 Yes this is the correct place at code, where a new handlebar helper can be added try this in our email editor
Total number of fruits is {{fruits.length}}
Total number of fruits is {{fruits.length}}
where payload is
{
"fruits" : ["Orange", "Apple", "Pineapple" ]
}
{
"fruits" : ["Orange", "Apple", "Pineapple" ]
}
Want results from more Discord servers?
Add your server