N
Novu12mo ago
Fabian B.

Workflows: Dynamically provide custom email template

Hi there! I want to build a workflow where I digest a few events and then send out an email with a list of those. I use Brevo (Sendinblue) to send these emails. I would like to either create the email templates 1. using Brevo (https://developers.brevo.com/docs/send-a-transactional-email#creating-your-api-request-using-brevo-api-clients) 2. or generate them by myself by feeding react-email/vue-email (which renders to html) with the events data and then send this email. Is there currently a way of doing this?
Brevo API
Send a transactional email
Learn how to send a transactional email for an existing template and adding dynamic content
12 Replies
Fabian B.
Fabian B.OP12mo ago
TLDR: Is there a way to execute an integration (sending an email) and customizing the parameters of this API call?
empe
empe12mo ago
Hey @Fabian B. To customize the parameters of an API call when executing an integration such as sending an email with Novu, you can use the overrides field in your trigger call. This allows you to specify the integrationIdentifier to select the email provider, such as Brevo (Sendinblue), and pass custom parameters like templateId and personalization if you're using a specific template from your email provider. For example, using a MailerSend template with Novu would look like this:
import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');

await novu.trigger("workflowIdentifier", {
to: "subscriberId",
payload: {},
overrides: {
email: {
customData: {
// mailersend template templateId
templateId: 'mailersend-template-id',
// mailersend template variables
personalization: [{
data: {
items: {
price: '',
product: '',
quantity: '',
},
order: {
date: '',
order_number: '',
billing_address: '',
customer_message: '',
},
store: {
name: '',
},
invoice: {
total: '',
subtotal: '',
pay_method: '',
},
customer: {
name: '',
email: '',
phone: '',
},
},
}],
},
}
},
// actorId is subscriberId of actor
actor: "actorId",
tenant: "tenantIdentifier"
});
import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');

await novu.trigger("workflowIdentifier", {
to: "subscriberId",
payload: {},
overrides: {
email: {
customData: {
// mailersend template templateId
templateId: 'mailersend-template-id',
// mailersend template variables
personalization: [{
data: {
items: {
price: '',
product: '',
quantity: '',
},
order: {
date: '',
order_number: '',
billing_address: '',
customer_message: '',
},
store: {
name: '',
},
invoice: {
total: '',
subtotal: '',
pay_method: '',
},
customer: {
name: '',
email: '',
phone: '',
},
},
}],
},
}
},
// actorId is subscriberId of actor
actor: "actorId",
tenant: "tenantIdentifier"
});
Also, please check the following section: https://docs.novu.co/channels-and-providers/email/overview#using-different-email-integration And this: https://docs.novu.co/channels-and-providers/email/overview#sending-email-overrides
Fabian B.
Fabian B.OP12mo ago
Thanks @Emil for the quick response! I will check if that will work 🙂
empe
empe11mo ago
Hey @Fabian B.! Did you manage to get your desired outcome?
Fabian B.
Fabian B.OP11mo ago
Thanks for getting back @Emil, unfortunately, I weren't able to get it to run. It still sends the html generated by Novu to Brevo. It does not use the template, even though I set it in the overrides request body. Besides that, I do not see it working with Digests nevertheless, because when you think of it, you're overriding a single event with the customData. In my case, Brevo should recieve an array of all data and loop through this array to generate the template. But imagine you have 10 events before the digest runs and sends the email, every event override would erase the event data before. So at the end, you would still only have one array element. Since I cannot add the step.events array to the customData override.
Fabian B.
Fabian B.OP11mo ago
This is the API request format Brevo expects. This works fine when sending directly to Brevo. For this to work, I would have to replace the "jobs" array in the screenshot with the step.events array from novu at the moment where the digest is running, not at the moment I send out the event.
No description
Novu_Bot
Novu_Bot11mo ago
@Fabian B., you just advanced to level 2!
Fabian B.
Fabian B.OP11mo ago
Just discovered that there is the "Email Webhook" integration, which I can use to send the event data to my API. I have to test it a bit but seems that solves my issue. Since I can then just call the brevo api myself
empe
empe11mo ago
@Fabian B. Once you done testing it, could you please share the results and your insights?
Fabian B.
Fabian B.OP11mo ago
Sure! So I have setuped a simple workflow like this. In the Webhook Settings, I pointed the URL to my server. Novu then sends me a webhook request when it would normally send out an email. The payload of this HTTP request contains the step.events array, which I can then use to send out the actual email with Brevo. This solution now works fine on my side, and I can still benefit from everything novu has to offer, especially the digest engine.
No description
No description
empe
empe11mo ago
That's lovely! Where do you think we could add this to in our documentation? cc: @Pawan Jain
Linear
Linear11mo ago
Want results from more Discord servers?
Add your server