N
Novu5mo ago
LUCKY

Echo Workflow Variants

Hi all I would like to try out Echo and was looking for a way how to specify variants in the docs, but didn’t find anything. Is this supported?
14 Replies
Ask Inkeep
Ask Inkeep5mo ago
Hi @LUCKY, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question.
Novu_Bot
Novu_Bot5mo ago
@LUCKY, you just advanced to level 3!
Ask Inkeep
Ask Inkeep5mo ago
----------------------------- While I generate an answer, here are some sources that might be helpful: * Variants * Roadmap * Workflows * Quick Start -----------------------------
Ask Inkeep
Ask Inkeep5mo ago
Answer Echo, as part of Novu's infrastructure, focuses on code-first notification workflow engines that allow for complex notification workflows to be crafted within your codebase. Echo provides a robust framework for defining and managing notification workflows but does not specifically mention or support "variants" as you've described within the context of Echo's documentation or functionalities (1) . For managing variants within workflows, Novu provides a feature called "Variants" in another part of its platform. This feature allows users to create multiple versions of a given workflow step, linked to specific conditions, which is essential for sending tailored notifications based on subscriber attributes or other contextual information (2) . However, this is explicitly mentioned in the context of Novu's general notification infrastructure rather than the Echo code-first engine. Given this, if you're looking to implement variants in the context of Echo, the current documentation does not explicitly cover this feature. Echo focuses more on the code-first approach to defining workflows and steps within your application, leveraging the power of Novu for notifications (1) . For detailed functionalities and the latest updates, it would be beneficial to check the official Novu documentation or reach out to the Novu community for more specific queries or feature requests (3) .
Ask Inkeep
Ask Inkeep5mo ago
Got it. Tagging @Support for additional help.
Dima Grossman
Dima Grossman5mo ago
Hi @LUCKY variants can actually just be an if statement in your workflow definition. Both for content and for configuration. Do you have a particular usecase in mind you are trying to achieve?
LUCKY
LUCKY5mo ago
Hey @Dima Grossman Many thanks for your reply Ah I see, I could use the payload and based on it write a different logic, makes sense. I am just trying out echo, as I like the code-first approach, attached a screenshots Quick question: - Will the end-result of Novu Framework always be the Cloud Configuration. It's basically, like terraform, but for Novu? - In my example, will it create 2 variants and for each email + push? Can users still modify and say that they want to disable email? - How can I define that I want to send it over OneSignal for push and SendGrid for Email? Many thanks!
No description
Dima Grossman
Dima Grossman5mo ago
You will need to add your if statements inside of your step functions and not outse, the workflow engine hydrates state so the workflow definition function should always have the same step structures The framework sdk will use your provider configurations from the cloud integrations page. So if you have email defined with sendgrid, it will use sendgrid User preferences work exactly like they work today, so if a user disabled email for a specific workflow in his preference it will be appleid to your workflow definition
LUCKY
LUCKY5mo ago
@Dima Grossman sorry, I don't fully understand the first point, do you mean like this?
/* eslint-disable max-len */
import { workflow } from "@novu/framework";

const isAbsenceLimitExceeded: boolean = false;

export const requestAbsence = workflow(
"request-absence",
async ({ step, payload }) => {
await step.push("request-absence", async () => {
if (isAbsenceLimitExceeded) {
// variant 1
return {
subject: "Absence Limit Exceeded",
body: `Absence limit exceeded for ${payload.name}.`,
};
} else {
// variant 2
return {
subject: "Request Absence",
body: `${payload.name} has requested absence from ${payload.startDate} to ${payload.endDate}.`,
};
}
});

await step.email("send-email", async () => {
if (isAbsenceLimitExceeded) {
// variant 1
return {
subject: "Absence Limit Exceeded",
body: `Absence limit exceeded for ${payload.name}.`,
};
} else {
// variant 2
return {
subject: "Request Absence",
body: `${payload.name} has requested absence from ${payload.startDate} to ${payload.endDate}.`,
};
}
});
},
{
payloadSchema: {
type: "object",
properties: {
name: { type: "string" },
startDate: { type: "string" },
endDate: { type: "string" },
},
required: ["name", "startDate", "endDate"],
},
} as const
);
/* eslint-disable max-len */
import { workflow } from "@novu/framework";

const isAbsenceLimitExceeded: boolean = false;

export const requestAbsence = workflow(
"request-absence",
async ({ step, payload }) => {
await step.push("request-absence", async () => {
if (isAbsenceLimitExceeded) {
// variant 1
return {
subject: "Absence Limit Exceeded",
body: `Absence limit exceeded for ${payload.name}.`,
};
} else {
// variant 2
return {
subject: "Request Absence",
body: `${payload.name} has requested absence from ${payload.startDate} to ${payload.endDate}.`,
};
}
});

await step.email("send-email", async () => {
if (isAbsenceLimitExceeded) {
// variant 1
return {
subject: "Absence Limit Exceeded",
body: `Absence limit exceeded for ${payload.name}.`,
};
} else {
// variant 2
return {
subject: "Request Absence",
body: `${payload.name} has requested absence from ${payload.startDate} to ${payload.endDate}.`,
};
}
});
},
{
payloadSchema: {
type: "object",
properties: {
name: { type: "string" },
startDate: { type: "string" },
endDate: { type: "string" },
},
required: ["name", "startDate", "endDate"],
},
} as const
);
LUCKY
LUCKY5mo ago
No description
Dima Grossman
Dima Grossman5mo ago
Yes! Another option if you still want to keep them seaparate to easily preview content in the UI, each step has a skip method. If you will use it, you will be seeing them as separate steps in the web editor
LUCKY
LUCKY5mo ago
@Dima Grossman thanks for helping me with the first workflow, I like the overall code-first concept. Can we use it with our self hosted Novu? Which Echo URL should we use? Many thanks
Dima Grossman
Dima Grossman5mo ago
Hi @LUCKY the OSS Community Edition will rollout around mid-or and July, we are doing a big release next week on cloud and OSS will come next
LUCKY
LUCKY5mo ago
@Dima Grossman many thanks for the update, great!
Want results from more Discord servers?
Add your server