Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework): Add workflow channel preferences docs #695

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions sdks/framework/typescript/workflow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,69 @@ workflow(
<ParamField path="tags" type="string[]">
The tags assigned to the workflow. Tags can be used to filter workflows in the dashboard, and can be used by channels such as Inbox to sort Notifications into different categories for a better user experience.
</ParamField>
<ParamField path="preferences" type="WorkflowPreferences">
The preferences for the workflow. Read more about [Workflow Channel Preferences](/sdks/framework/typescript/workflow#workflow-channel-preferences).
<Expandable title="properties">
<ParamField path="all" type="WorkflowPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the workflow.
If `true`, notification delivery is enabled by default for all channels.
This setting can be overridden by the channel preferences.
</ParamField>
<ParamField path="readOnly" type="boolean" default="false">
A flag specifying if the preferences are read-only.
If `true`, the preferences cannot be changed by the subscriber.
</ParamField>
</Expandable>
</ParamField>
<ParamField path="channels" type="ChannelPreferences">
The preferences for the workflow. Read more about [Workflow Channel Preferences](/sdks/framework/typescript/workflow#workflow-channel-preferences).
<Expandable title="properties">
<ParamField path="inApp" type="ChannelPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the in-app channel.
If `true`, notification delivery is enabled by default.
</ParamField>
</Expandable>
</ParamField>
<ParamField path="email" type="ChannelPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the email channel.
If `true`, notification delivery is enabled by default.
</ParamField>
</Expandable>
</ParamField>
<ParamField path="sms" type="ChannelPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the SMS channel.
If `true`, notification delivery is enabled by default.
</ParamField>
</Expandable>
</ParamField>
<ParamField path="chat" type="ChannelPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the chat channel.
If `true`, notification delivery is enabled by default.
</ParamField>
</Expandable>
</ParamField>
<ParamField path="push" type="ChannelPreference">
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default="true">
A flag specifying if notification delivery is enabled for the push channel.
If `true`, notification delivery is enabled by default.
</ParamField>
</Expandable>
</ParamField>
</Expandable>
</ParamField>
</Expandable>
</ParamField>
</Expandable>

</ParamField>
Expand Down Expand Up @@ -96,3 +159,145 @@ This context is passed by the workflow engine to provide contextual information
The object that contains all the step functions, read more at [Step
Functions](/sdks/framework/typescript/steps/introduction).
</ParamField>

### Workflow Channel Preferences

By default, Novu will show the subscriber preferences in the Inbox component. Subscribers can enable and disable any active channel in the workflow using subscriber preferences.
With Workflow channel preferences, you can control the default delivery preference for a channel and whether a subscriber can change it.

In the `all` object, you can specify default preferences for all channels. The `enabled` field on the `all` object is used as fallback value if a channel is not specified explicitly in `channels`. The `readOnly` field controls whether subscribers can change the delivery preference for a channel.

In the `channels` object, you can specify In-App, SMS, Email, Chat, and Push channel preferences. Each channel takes an object with an optional `enabled` flag that controls whether a notification delivery channel is enabled or disabled by default for subscribers.

By default, `enabled` is `true` and `readOnly` is `false` at `all` and `channels` level.

These preferences can also be controlled from the Novu Dashboard on a workflow. To do so, click on the cog icon at the top right of your screen, and then select the "Preferences" tab.

<Tabs>
<Tab title="Default">
```typescript
const newWorkflow = workflow(
'default-preferences',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
all: { enabled: true, readOnly: false },
channels: {
inApp: { enabled: true },
email: { enabled: true },
sms: { enabled: true },
chat: { enabled: true },
push: { enabled: true },
},
}
},
}
);
```
</Tab>
<Tab title="In-App Only - Editable">
```typescript
const newWorkflow = workflow(
'only-in-app-channel',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
all: { enabled: false },
channels: {
inApp: { enabled: true },
},
}
},
}
);
```
</Tab>
<Tab title="All Enabled - Editable">
```typescript
const newWorkflow = workflow(
'all-enabled-editable',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
all: { enabled: true },
}
},
}
);
```
</Tab>
<Tab title="All Enabled - Read Only">
```typescript
const newWorkflow = workflow(
'all-enabled-read-only',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
all: { enabled: true, readOnly: true },
}
},
}
);
```
</Tab>
<Tab title="All Disabled - Editable">
```typescript
const newWorkflow = workflow(
'all-disabled-editable',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
all: { enabled: false, readOnly: false },
}
},
}
);
```
</Tab>
<Tab title="In-App Disabled - Editable">
```typescript
const newWorkflow = workflow(
'in-app-disabled-editable',
async ({ step }) => {
await step.inApp('send-in-app', () => ({
body: 'Hello there',
}));
},
{
preferences: {
{
channels: {
inApp: { enabled: false },
},
}
},
}
);
```
</Tab>
</Tabs>