Is it possible to use groupBy with step.events?

Pretty much title. I have a workflow with a digest running, and I followed the docs for the count excluding individuals:
{{#each step.events}}
{{#if @first}}
{{this.name}}
{{else}}
{{#if @last}}
and {{@index}}
{{/if}}
{{/if}}
{{/each}}
followed you!
{{#each step.events}}
{{#if @first}}
{{this.name}}
{{else}}
{{#if @last}}
and {{@index}}
{{/if}}
{{/if}}
{{/each}}
followed you!
But in this case, this is for a one-time event. I am trying to notify messages received, like in a chat. So the same user can send many messages, that got digested and sent. The problem in that snippet, in my situation, is that if I send 5 messages, I will receive the notification as Person1 and 4 other sent a message, but I was the one that sent the 5 messages. I was thinking about using the groupBy title, but since I'm having the digest and doing a each step.events, i got stuck. Can someone help or know if this is possible?
4 Replies
Pawan Jain
Pawan Jain12mo ago
Hi @Obscene Burrito groupBy can be used to group the array items in one group by propery you can use array length for counting messages https://docs.novu.co/content-creation-design/handlebars-helpers#using-array-length-as-count
Obscene Burrito
Obscene BurritoOP12mo ago
Yeah, i know. My question is if it's possible to use groupBy with #each step.events. As I mentioned before, this is what happens nowadays: The problem in that snippet, in my situation, is that if I send 5 messages, I will receive the notification as Person1 and 4 other sent a message, but I was the one that sent the 5 messages. and i want to have the unique values in this case
Pawan Jain
Pawan Jain12mo ago
@Obscene Burrito could you share your payload ?
Obscene Burrito
Obscene BurritoOP12mo ago
yes! this is what i'm doing:
{{#equals step.total_count 1}}
{{#each step.events}}
You have new messages from {{contactLabel}}.
{{/each}}
{{else}}
Open your inbox to view recent messages.
{{/equals}}
{{#equals step.total_count 1}}
{{#each step.events}}
You have new messages from {{contactLabel}}.
{{/each}}
{{else}}
Open your inbox to view recent messages.
{{/equals}}
` but i'd like to do something like:
{{#equals step.total_count 1}}
{{#each step.events}}
You have new messages from {{contactLabel}}.
{{/each}}
{{else}}
{{#each groupBy step.events.??? "contact"}}
Open your inbox to view recent messages.
{{/each}}
{{/equals}}
{{#equals step.total_count 1}}
{{#each step.events}}
You have new messages from {{contactLabel}}.
{{/each}}
{{else}}
{{#each groupBy step.events.??? "contact"}}
Open your inbox to view recent messages.
{{/each}}
{{/equals}}
Want results from more Discord servers?
Add your server