Skip to content

Commit

Permalink
Merge pull request #3800 from novuhq/feature/add-scheduled-digest
Browse files Browse the repository at this point in the history
feat: add scheduled ⏰ digest documentation and images
  • Loading branch information
jainpawan21 authored Aug 21, 2023
2 parents 5559005 + 8ea5e09 commit a070c2f
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 38 deletions.
7 changes: 6 additions & 1 deletion docs/docs/channels/email/resend.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ Resend allows you to authenticate your sender identity using [Domain Authenticat
- Visit the [Integrations](https://web.novu.co/integrations) page on Novu.
- Locate Resend and click on the **Connect** button.
- Enter your Resend API Key.
- Fill the `From email address` field using the authenticated email from the previous step.
- If you have verified your domain in previous step, fill the `From email address` field with any domain email address. For example, if your organization domain name is `linear.app` then you can use any valid email address like `[email protected]`.
- For testing, you can use `[email protected]` if you have not authenticated your sender identity.
- Fill the `Sender name`.

:::info
Resend does not support sender name field separately. To show your preferred `Sender Name` in emails, enter `Team Linear <[email protected]>` in `From email address` field instead of `[email protected]`. Here **Team Linear** is `Sender Name`.
:::

- Click on the `Disabled` button and mark as `Active`.
- Click on the **Connect** button.
- You should now be able to send notifications using Resend in Novu.
21 changes: 8 additions & 13 deletions docs/docs/platform/delay.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ sidebar_position: 8

The delay action awaits a specified amount of time before moving on to trigger the following steps of the workflow.

<iframe width="560" height="315" src="https://www.youtube.com/embed/kCMB-WdbzJo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
<iframe width="100%" height="315" src="https://www.youtube.com/embed/kCMB-WdbzJo" title="Delay Action Step - Novu Workflow" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

## Delay Node

After adding a delay node in the workflow editor, the immediate next step will only be triggered after the specified period of time has elapsed.

### Node configurations
## Delay Types

### Regular Delay

Regular Delay will determine how long it will take before triggering the next step.
Regular Delay will determine how long it will take before triggering the next step.You can specify the amount and time interval unit that best suits your needs.

#### Time Interval
![Regular Delay](/img/platform/delay/regular-delay.png)

You can specify the amount and time unit that best suits your needs.
> **Overriding regular delay value**
Should you wish to, you could override the default delay time interval you set in the creation of the delay node.
You can override the default delay time interval you set adding delay action node in workflow.

```typescript
novu.trigger('template-name', {
Expand All @@ -45,15 +45,12 @@ novu.trigger('template-name', {

Scheduled Delay allows delaying up to a future date before continuation of steps execution. All steps after delay node will be triggered only after said date.

#### Payload Path
> **Payload Path**
Payload path will determine the path in payload for the scheduled date.

That path must be included in your payload on trigger execution and must be a date in strict ISO format.

For example:

![Workflow Photo](/img/scheduled-delay.png)
![Scheduled Delay](/img/platform/delay/scheduled-delay.png)

```typescript
novu.trigger('workflow-name', {
Expand All @@ -67,7 +64,5 @@ novu.trigger('workflow-name', {
```

:::info

Date must be in ISO date format of YYYY-MM-DD**T**hh:mm:ss.SSS**Z**

:::
99 changes: 75 additions & 24 deletions docs/docs/platform/digest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,91 @@ sidebar_position: 6

# Digest Engine

The digest engine collects multiple trigger events, aggregates them into a single message and delivers it to the subscriber.
The digest engine collects multiple trigger events, aggregates them into a single message, and delivers it to the subscriber. Another name of the digest can be `batch`.

This becomes useful when a user needs to be notified on a large amount of triggers and you want to avoid sending too many notifications. Novu will automatically batch the incoming trigger events based on the `subscriberId` and an **optional** `digestKey` that can be added to control the digestion of the events.
This becomes useful when a user needs to be notified of many activities and you don't want to send notifications for each activity. Novu will batch the incoming trigger events based on the `subscriberId` by default and an **optional** `digestKey` that can be added to control the digestion of the events.

## Digest Node

After adding a digest node in the workflow editor, each node that will be below the digest node will be only triggered once in the specified digest interval. You can decide to send messages before adding a digest node and they will be triggered in real-time.
After adding a digest node in the workflow editor, each node that will be below the digest node will be only triggered once in the specified digest interval.

![Workflow Photo](/img/digest-flow.png)
In the below image workflow, there are two nodes (`email` and `sms`) after the digest node and one node (`in-app`) before the digest node in the workflow. For this workflow, if we trigger 10 events within the digest interval, the `in-app` step will be executed 10 times, and `email` and `sms` will be executed only 1 time with digested events data.

### Node configurations
![Workflow Photo](/img/platform/digest/digest-nodes.png)

#### Time Interval
## Digest Key

Will determine how long the digest engine will wait before sending the message once created. You can specify the amount and the unit that best suits your needs.
By default, Novu digests events based on the `subscriberId`. Users can use a single or group of custom keys. More than one key can be written as comma-separated words. With custom keys, Novu will digest events on the basis of the combination of subscriberId and all custom keys. Custom keys can be nested as well as non-nested.

#### Digest Key
In the below image, `author.name` is a nested key, and `postId` is a non-nested key. When this workflow is triggered, the payload must contain `author.name` and `postId` fields to aggregate digest events based on these keys.

If specified, the digest engine will group the events based on the `digestKey` and `subscriberId`, otherwise the digest engine will group the events based only on the subscriberId.
![Custom Digest Keys](/img/platform/digest/custom-digest-keys.png)

The digest key might come useful when you want a particular subscriber to get events grouped on a custom field. For example when an actor likes the user's post, you might want to digest based on the `post_id` key.
## Digest Types

#### Strategy
### Regular Digest

The strategy which Novu should use handle the digest step. More details on available strategies below.
Regular Digest digests events for specified time interval. After the time interval is complete, the digest node forwards digested events to the next node. Here, in the below example image, `2` is the `interval amount`, and `mins` is the `interval unit`. Interval units can be sec(s), min(s), hour(s), or day(s).

## Strategies
![Regular Digest](/img/platform/digest/regular-digest.png)

Novu allows you to define different digest strategies depending on the actual use-case you are trying to achieve. At this point we allow you to select from 2 strategies:
:::info
If you create a digest with 8 hours digest interval and then trigger a few events a new digest will be created that will digest events for the next 8 hours. Now before 8 hours, you reduce digest interval to 2 minutes. Now new events will still merge with the previous 8 hours digest because even after changing the interval to 2 minutes, that old 8 hours digest is still active. You have to cancel the first event using [this API](https://docs.novu.co/api/cancel-triggered-event/) to remove that 8 hours digest. **Use short duration time interval for digest testing purposes**.
:::

- Regular Strategy
- Back-off Strategy
### Backoff Digest

Let's explore them in detail:
Backoff digest has two intervals `digest interval` and `backoff interval`. Here, in the below image, the `digest interval` is 20 minutes, and the `backoff interval` is 15 minutes. In the case of a backoff digest, first, it is checked if any event is triggered within the past backoff interval, only then a digest is created for the digest interval. If not, the event is considered non-digest and workflow execution continues to the next step.

### Regular Strategy
![Backoff Digest](/img/platform/digest/backoff-digest.png)

In regular strategy, a digest will always be created for the specified window time. Which means that from the first event trigger, if no active digest exists for this subscriber, one will be created and the user will receive the message only when the digest window time is reached.
`Example:`

### Back-off Strategy
Let's set the digest interval as 20 minutes and the backoff time as 15 minutes.

In the back-off strategy, before creating a digest, Novu will check if a message was sent to the user in the back-off period. If a message was sent, a digest will be created. Otherwise, a message will be sent directly to the user and the digest creation will be skipped.
If we trigger the first event. Since it is the first event and there was no event triggered in the past 15 minutes (backoff interval), this event will be executed as it is (without digest).

Now, if we trigger a second within 15 minutes, then a new digest will be created with this second event. From now onwards till 20 minutes (digest interval), all triggers will be digested in this digest, and after 20 minutes, the workflow will carry forward to the next step with digested events.

### Scheduled Digest

- **Minutes**

It digests events for every specified minutes. For example, as per the below image, events will be digested for 20 minutes and after 20 minutes, workflow will carry forward to the next step. It will be repeated after every 20 minutes.

![Scheduled Digest Min](/img/platform/digest/scheduled-digest-min.png)

- **Hour**

It digests events for given hours. After given hours, a new digest is created.

![Scheduled Digest Hour](/img/platform/digest/scheduled-digest-hour.png)

- **Daily**

It digests events for specified days till given time. After those days and time, a new digest is created and events are digested in this new digest.

:::info
Time is in UTC timezone for the `daily`, `weekly`, and `monthly` scheduled digest.
:::

![Scheduled Digest Daily](/img/platform/digest/scheduled-digest-daily.png)

- **Weekly**

It digests events for specified weekdays. Only at the specified time, the workflow continues to the next step after the digest step. A new digest is created and events are digested in this new digest till these weeks and time.

![Scheduled Digest Weekly](/img/platform/digest/scheduled-digest-weekly.png)

- **Monthly**

![Scheduled Digest Monthly](/img/platform/digest/scheduled-digest-monthly.gif)

## Writing digest templates

In many cases, you will need to access all the digested events payload in order to show the user all or parts of the events included in this digest. For example: "John and 5 others liked your photo."
In many cases, you will need to access all the digested events payload in order to show the user all or parts of the events included in this digest. For example: **John and 5 others liked your photo.**

As part of the digested template, you will have access to a few properties:
As part of the digested template, you will have access to these properties:

| Property | Description |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -77,6 +114,14 @@ novu.trigger('workflow-name', {
});
```

After these two triggers, digest variables are as follows:

| Property | Value |
| ------------------ | --------------------------------------------- |
| `step.events` | [ { "name" : "Hello" }, { "name": "World" } ] |
| `step.total_count` | 2 |
| `step.digest` | true |

Using the following template:

```handlebars
Expand All @@ -85,11 +130,17 @@ Total events in digest:
{{#if step.digest}}
{{#each step.events}}
{{name}}
<div>This is {{name}} payload event</div>
{{/each}}
{{else}}
Not a digested template
{{/if}}
```

It will renders as :

```html
Total events in digest: 2 This is Hello payload event This is World payload event
```

Note that if only one matching trigger activates a regular digest during its period, that single item will still come through as a digest with `step.total_count` as 1.
Binary file removed docs/static/img/digest-flow.png
Binary file not shown.
Binary file added docs/static/img/platform/delay/regular-delay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/platform/digest/digest-nodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/static/img/scheduled-delay.png
Binary file not shown.

0 comments on commit a070c2f

Please sign in to comment.