N
Novu2mo ago
Dragan

Hello,

I want to use SendGrid dynamic templates along with code first workflows and digest as one of the steps. The problem I am facing is that we need to pass in the templateId and the dynamic data when triggering the workflow. Is there a way to pass in the digestResult to the SendGrid template?
13 Replies
Ask Inkeep
Ask Inkeep2mo ago
Hi @Dragan, 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. ----------------------------- While I generate an answer, here are some sources that might be helpful: * SendGrid * Collect multiple events to a single message with the Digest Engine * Digest Action Step * How to Add Digest to Email Notifications ----------------------------- Answer Yes, it is possible to use SendGrid dynamic templates with code-first workflows and digest steps in Novu. (1) You can pass the SendGrid template ID and dynamic data when triggering the workflow using the customData field in the email overrides. Using SendGrid Templates To use a SendGrid template, you can include the template details in the customData field of the email overrides when triggering the workflow. Here's an example of how you can do this:
import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');
await novu.subscribers.trigger("workflowIdentifier", {
to: "subscriberId",
payload: {},
overrides: {
email: {
customData: {
// sendgrid template templateId
templateId: 'sendgrid-template-id',
// sendgrid template variables
dynamicTemplateData: {
// Your dynamic data here
},
},
}
},
// actorId is subscriberId of actor
actor: "actorId"
tenant: "tenantIdentifier"
});
import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');
await novu.subscribers.trigger("workflowIdentifier", {
to: "subscriberId",
payload: {},
overrides: {
email: {
customData: {
// sendgrid template templateId
templateId: 'sendgrid-template-id',
// sendgrid template variables
dynamicTemplateData: {
// Your dynamic data here
},
},
}
},
// actorId is subscriberId of actor
actor: "actorId"
tenant: "tenantIdentifier"
});
Passing Digest Results To pass the digest results to the SendGrid template, you can use the digest step in your workflow and then access the digest results in the subsequent email step. (2) Here's how you can structure your workflow: 1. Define a digest step in your workflow. 2. In the email step after the digest, you can access the digest results and include them in the dynamicTemplateData. Here's an example of how you might structure this in your workflow:
Ask Inkeep
Ask Inkeep2mo ago
import { workflow } from '@novu/framework';

workflow('id', async ({ step, payload }) => {
const digestResult = await step.digest("digest", async () => {
return {
amount: 1,
unit: 'hours',
}
});

await step.email("send-email", async () => {
return {
subject: "Digest Email",
customData: {
templateId: 'sendgrid-template-id',
dynamicTemplateData: {
digestEvents: digestResult.events,
// Add any other dynamic data you need
},
},
};
});
});
import { workflow } from '@novu/framework';

workflow('id', async ({ step, payload }) => {
const digestResult = await step.digest("digest", async () => {
return {
amount: 1,
unit: 'hours',
}
});

await step.email("send-email", async () => {
return {
subject: "Digest Email",
customData: {
templateId: 'sendgrid-template-id',
dynamicTemplateData: {
digestEvents: digestResult.events,
// Add any other dynamic data you need
},
},
};
});
});
(2) (3) In this example, digestResult.events contains an array of the digested events, which you can pass to your SendGrid template. (2) Remember to adjust the template ID and dynamic data structure according to your specific SendGrid template requirements. (1)
Ask Inkeep
Ask Inkeep2mo ago
Feel free to tag @Ask Inkeep with additional questions.
Pawan Jain
Pawan Jain2mo ago
@Dragan Here you are looking to use SendGrid dynamic templates or just want to change email content text while triggering? in case of sendgrid dynamic template, templateId and dynamic data is required filed, you can use digestResult response in dynamicdata
Dragan
Dragan2mo ago
@Pawan Jain I am trying to use SendGrid dynamic template. I just can't get the data from the email step. The above solution did not work. await step.email('send-email', async () => { return { subject: 'New email', body: '', customData: { templateId: 'sendgrid-template-id', dynamicTemplateData: { name: 'some data', updatedBy: 'John Wick', }, }, }; }); I this is my step definition but I don't seem to get the values in sendgrid this is what is sent based on the activity feed: { "name": "some-workflow", "to": { "subscriberId": "2" }, "payload": { "name": "Name1", "updatedBy": "Dragan" }, "overrides": { "email": { "customData": { "templateId": "sendgrid-template-id", "dynamicTemplateData": { "name": "Name from trigger" } } } } }
Novu_Bot
Novu_Bot2mo ago
@Dragan, you just advanced to level 1!
Dragan
Dragan2mo ago
when I get the mail only the variables from the overrides are populated the dynamicTemplateData from the email step never seem to make it to sendgrid
Dima Grossman
Dima Grossman2mo ago
Hi @Dragan !
Dima Grossman
Dima Grossman2mo ago
This will be possible with step provider overrides in the framework SDK: https://docs.novu.co/sdks/framework/typescript/steps/introduction#providers-overrides-object
Dima Grossman
Dima Grossman2mo ago
Unfortuently we only support passing the the ipPoolName at the moment In about 1-2 weeks, we will release the interface to pass any provider custom SDK properties (including all the other Sendgrid available SDKS) I will update you once this becomes available 🙏
await step.email("send-email", async () => {
return {
subject: "Digest Email",

};
}, {
providers: {
sendgrid: () => {
return {
"templateId": "sendgrid-template-id",
"dynamicTemplateData": {
"name": "Name from trigger"
}
}
}
}
});
await step.email("send-email", async () => {
return {
subject: "Digest Email",

};
}, {
providers: {
sendgrid: () => {
return {
"templateId": "sendgrid-template-id",
"dynamicTemplateData": {
"name": "Name from trigger"
}
}
}
}
});
Here is the interface for when it's available
Dragan
Dragan2mo ago
Hi @Dima Grossman , thanks for the clarification.
Dragan
Dragan2mo ago
As a side note: the chatbot gives false/inaccurate data for this topic.
No description
No description
Dima Grossman
Dima Grossman2mo ago
Yes ^ @Pawan Jain can we reindex the bot or disable it?
Want results from more Discord servers?
Add your server