N
Novu•3w ago
christian

Using Subscriber in Topic trigger

Hi, When triggering a topic, is it possible to access the subscriberId and firstname? Trying to send an e-mail every week to all subscribers using a topic but want to include the firstName in the e-mail.
6 Replies
Pawan Jain
Pawan Jain•3w ago
@christian Yes subscriberId and firstname can be used when triggering to a topic. Internally novu fanout the trigger request to subscribers of topic. Are you using @novu/framework based workfllows?
christian
christianOP•3w ago
yes this is my workflow
import { renderEmail } from "@kickstarted/email/emails/top-recipes";
import { workflow } from "@novu/framework";
import { TriggerEvents, topWeeklyPayloadSchema } from "../schemas";

export const topRecipesWorkflow = workflow(
TriggerEvents.TopWeekly,
async ({ step, payload, subscriber }) => {
const recipes = JSON.parse(payload.recipes ?? "[]");
const userId = subscriber.subscriberId ?? "";
const userFirstName = subscriber.firstName ?? "";

await step.email("weekly-top-recipes", async () => {
const emailBody = await renderEmail(recipes, userId, userFirstName);
return {
subject: "Top recipes last week",
body: emailBody,
};
});
},
{
payloadSchema: topWeeklyPayloadSchema,
},
);
import { renderEmail } from "@kickstarted/email/emails/top-recipes";
import { workflow } from "@novu/framework";
import { TriggerEvents, topWeeklyPayloadSchema } from "../schemas";

export const topRecipesWorkflow = workflow(
TriggerEvents.TopWeekly,
async ({ step, payload, subscriber }) => {
const recipes = JSON.parse(payload.recipes ?? "[]");
const userId = subscriber.subscriberId ?? "";
const userFirstName = subscriber.firstName ?? "";

await step.email("weekly-top-recipes", async () => {
const emailBody = await renderEmail(recipes, userId, userFirstName);
return {
subject: "Top recipes last week",
body: emailBody,
};
});
},
{
payloadSchema: topWeeklyPayloadSchema,
},
);
Pawan Jain
Pawan Jain•3w ago
Are you facing any issue with above code? it should work
christian
christianOP•3w ago
yes userid and firstname is empty, I will try to debug it to see if there's anything in the subscriber object I think it's working and the problem was on my side 🙂 btw: get subscriber api
Query Parameters
includeTopics
string
Includes the topics associated with the subscriber
Query Parameters
includeTopics
string
Includes the topics associated with the subscriber
should be boolean
Pawan Jain
Pawan Jain•3w ago
Let me check this one
Want results from more Discord servers?
Add your server