Sending One-Time Passwords (OTP) is often unnecessarily complicated, requiring engineering teams to waste valuable development cycles setting up SMS infrastructure and getting email reputation satisfactory for sending six digit passcodes. This three channel workflow example shows how to send an email, push notification, or SMS OTP.
import { workflow } from '@novu/framework';
import { renderOtpEmail } from '../emails/slack-otp';
import { zodControlSchema, zodPayloadSchema, zodPushControlSchema, zodSmsControlSchema } from './schemas';
export const SlackVerificationOTP = workflow(
"Slack Verify OTP",
async ({ step, payload }) => {
await step.email(
"send-email",
async (controls) => {
return {
subject: controls.emailSubject,
body: renderOtpEmail(controls, payload),
};
},
{
controlSchema: zodControlSchema
});
await step.push('send-push', async (controls) => {
return {
subject: controls.pushNotificationSubject,
body: `Your verification code from Slack is ${payload.validationCode}`,
};
},
{
controlSchema: zodPushControlSchema
});
await step.sms('send-sms', async (controls) => {
return {
subject: controls.smsSubject,
body: `Your verification code from Slack is ${payload.validationCode}`,
};
},
{
controlSchema: zodSmsControlSchema
});
},
{
payloadSchema: zodPayloadSchema
},
);