Workflow payload is the data passed during the novu.trigger
method. This is useful for ensuring that the payload is correctly formatted and that the data is valid.
Payload Schema
Payload schema is defining the payload passed during the novu.trigger
method. This is useful for ensuring that the payload is correctly formatted and that the data is valid.
workflow('comment-on-post', async ({ step, payload }) => {
await step.email(
'send-email',
async () => {
return {
subject: `You have a new comment from: ${payload.author_name}.`,
body: render(<ReactEmailContent comment={payload.comment} />),
}
});
},
{
payloadSchema: {
type: 'object',
properties: {
post_id: { type: 'number' },
author_name: { type: 'string' },
comment: { type: 'string', maxLength: 200 },
},
required: ['post_id', 'comment'],
additionalProperties: false,
} as const,
},
);
Passing Payload
Here is an example of the validated payload during trigger:
novu.trigger('comment-on-post', {
to: 'subscriber_id',
payload: {
post_id: 1234,
author_name: 'John Doe',
comment: 'Looks good!'
}
});