await step.digest('digest', async (controls) => {
    return {
        amount: 1,
        unit: 'hours'
    }
});
const { events } = await step.digest('digest', resolver);

const {
    id,
    time,
    payload
} = events[0];

The digest step allows you to group events by a specified key and digest them together. This is useful when you need to group events by a specific key, such as a user ID, and then digest them together.

The result of the digest step is an array of events that have been digested together, allowing you to create a single notification for each group of events.

await step.digest('digest', async (controls) => {
    return {
        amount: 1,
        unit: 'hours'
    }
});
const { events } = await step.digest('digest', resolver);

const {
    id,
    time,
    payload
} = events[0];

Digest Step Output

Regular Digest

amount
number
required

This combined with the unit field determines the amount of time to digest events for.

unit
Enum: 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months'
required

The measurement unit for the amount field.

digestKey
string

This key is used to group events for the digest engine, if not provided all events will be digested together on the subscriber level. When provided, events will be grouped by the subscriberId and the digestKey.

The digest key must match the payloadSchema key provided on the workflow.

lookbackWindow
LookBackWindow

An example of a parameter field

Scheduled Digest

cron
string
required

The cron expression to schedule the digest on a repeating basis.

@novu/framework SDK exports a utility enum called CronExpression to help you build cron expressions.

import { CronExpression } from '@novu/framework';

await step.digest('digest', async (controls) => {
    return {
        cron: CronExpression.EVERY_DAY_AT_1AM
    }
});
digestKey
string

This key is used to group events for the digest engine, if not provided all events will be digested together on the subscriber level. When provided, events will be grouped by the subscriberId and the digestKey.

Digest Step Result

events
array

An array of triggers that have been digested.