sendgrid templates
export const testWorkflow = workflow(
"test-workflow",
async ({ step, payload }) => {
// First email - Welcome
await step.email("welcome-email", async () => ({
subject: `Welcome aboard!, ${payload.userName}`,
body: "Welcome to our community!",
customData: {
templateId: "d-fdb779e07e084227aa3d9cd79e08c8ac", // Welcome template
dynamicTemplateData: {
subject: `Welcome aboard!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
// First delay
await step.delay("delay-1", () => ({
type: "regular",
unit: "seconds",
amount: 15,
}));
// Second email - Getting Started
await step.email("followup-email", async () => ({
subject: `Let's get started!, ${payload.userName}`,
body: "Here's steps to get started!",
customData: {
templateId: "d-second_template_id", // Replace with your second template ID
dynamicTemplateData: {
subject: `Let's get started!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
// Second delay
await step.delay("delay-2", () => ({
type: "regular",
unit: "seconds",
amount: 15,
}));
// Third email - Profile Completion
await step.email("final-email", async () => ({
subject: `Time to shine!, ${payload.userName}`,
body: "Here's how to shine!",
customData: {
templateId: "d-third_template_id", // Replace with your third template ID
dynamicTemplateData: {
subject: `Time to shine!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
},
{
payloadSchema: z.object({
userName: z.string().default("Boilerplate User Name"),
}),
},
);
export const testWorkflow = workflow(
"test-workflow",
async ({ step, payload }) => {
// First email - Welcome
await step.email("welcome-email", async () => ({
subject: `Welcome aboard!, ${payload.userName}`,
body: "Welcome to our community!",
customData: {
templateId: "d-fdb779e07e084227aa3d9cd79e08c8ac", // Welcome template
dynamicTemplateData: {
subject: `Welcome aboard!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
// First delay
await step.delay("delay-1", () => ({
type: "regular",
unit: "seconds",
amount: 15,
}));
// Second email - Getting Started
await step.email("followup-email", async () => ({
subject: `Let's get started!, ${payload.userName}`,
body: "Here's steps to get started!",
customData: {
templateId: "d-second_template_id", // Replace with your second template ID
dynamicTemplateData: {
subject: `Let's get started!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
// Second delay
await step.delay("delay-2", () => ({
type: "regular",
unit: "seconds",
amount: 15,
}));
// Third email - Profile Completion
await step.email("final-email", async () => ({
subject: `Time to shine!, ${payload.userName}`,
body: "Here's how to shine!",
customData: {
templateId: "d-third_template_id", // Replace with your third template ID
dynamicTemplateData: {
subject: `Time to shine!, ${payload.userName}`,
fullName: payload.userName,
userName: payload.userName,
currentDate: new Date().toLocaleDateString(),
unsubscribe: "https://www.google.com",
preferences: "https://www.google.com/preferences",
},
},
}));
},
{
payloadSchema: z.object({
userName: z.string().default("Boilerplate User Name"),
}),
},
);
6 Replies
cannot seem to override anything to get different template Id's
integrating with sendgrid templates with novu is a bit of a nightmare
gonna try react-emails
@followbl
Checkout this example
export const sendGridOverridesEmail = workflow(
"sendgrid-email-overrides",
async ({ step, payload }) => {
await step.email(
"sendgrid-email-overrides",
async () => {
return {
subject: "SendGrid Overrides",
body: "this email tests sendgrid overrides",
};
},
{
providers: {
sendgrid: ({}) => ({
_passthrough: {
body: {
templateId: payload.dynamicTemplateId,
dynamicTemplateData: {
total: "$ 239.85",
items: [
{
text: payload.itemName,
image:
"https://marketing-image-production.s3.amazonaws.com/uploads/8dda1131320a6d978b515cc04ed479df259a458d5d45d58b6b381cae0bf9588113e80ef912f69e8c4cc1ef1a0297e8eefdb7b270064cc046b79a44e21b811802.png",
price: "$ 79.95",
},
{
text: "Old Line Sneakers rlfjrjrh4hr4rh4",
image:
"https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png",
price: "$ 79.95",
},
],
receipt: true,
name: "Sample Name",
address01: "1234 Fake St.",
address02: "Apt. 123",
city: "Place",
state: "CO",
zip: "80202",
},
},
},
}),
},
}
);
},
{
payloadSchema: z.object({
itemName: z.string().default("New Line Sneakers"),
dynamicTemplateId: z
.string()
.default("d-d965b02b1b5d4856bf332a5e98c7470c"),
}),
}
);
export const sendGridOverridesEmail = workflow(
"sendgrid-email-overrides",
async ({ step, payload }) => {
await step.email(
"sendgrid-email-overrides",
async () => {
return {
subject: "SendGrid Overrides",
body: "this email tests sendgrid overrides",
};
},
{
providers: {
sendgrid: ({}) => ({
_passthrough: {
body: {
templateId: payload.dynamicTemplateId,
dynamicTemplateData: {
total: "$ 239.85",
items: [
{
text: payload.itemName,
image:
"https://marketing-image-production.s3.amazonaws.com/uploads/8dda1131320a6d978b515cc04ed479df259a458d5d45d58b6b381cae0bf9588113e80ef912f69e8c4cc1ef1a0297e8eefdb7b270064cc046b79a44e21b811802.png",
price: "$ 79.95",
},
{
text: "Old Line Sneakers rlfjrjrh4hr4rh4",
image:
"https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png",
price: "$ 79.95",
},
],
receipt: true,
name: "Sample Name",
address01: "1234 Fake St.",
address02: "Apt. 123",
city: "Place",
state: "CO",
zip: "80202",
},
},
},
}),
},
}
);
},
{
payloadSchema: z.object({
itemName: z.string().default("New Line Sneakers"),
dynamicTemplateId: z
.string()
.default("d-d965b02b1b5d4856bf332a5e98c7470c"),
}),
}
);
nice, will check that out
@followbl
Let me know if you face any issue
will do, Novu is awesome
@followbl, you just advanced to level 1!