NovuN
Novu11mo ago
followbl

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"),
    }),
  },
);


this does not work, if this is triggered it won't use the templateId at all
Was this page helpful?