github novuhq/novu v0.2.5
v0.2.5 - The tiny cake release  🍰

latest releases: v2.0.1, v2.0.0, v0.24.3...
3 years ago

What's Changed

Other changes

Custom template function

In some cases, if you want to use your own template engine and not the built handlebars compiler, you can pass a function as the template in the message object.

await templateStore.addTemplate({
    id: 'test-notification-promise',
    messages: [
      {
        subject: '<div>{{firstName}}</div>',
        channel: ChannelTypeEnum.EMAIL,
        template: (trigger: ITriggerPayload) => {
            return `Custom rendered HTML`
        }
      },
    ],
  });

Validate trigger variables

From this version, you can run a validator for the ITriggerPayload passed to each message.

class JoiValidator extends IMessageValidator {
   constructor(private joiSchema) {}

   async validate(payload) {
     const { error } = this.joiSchema.validate(payload);
     if (error) throw new Error(error);

     return true;
   }
}

await templateStore.addTemplate({
    id: 'test-notification-promise',
    messages: [
      {
        validator: new JoiValidator(Joi.object({
             firstName: Joi.string(),
             lastName: Joi.string().required(),
       })),
        subject: '<div>{{firstName}}</div>',
        channel: ChannelTypeEnum.EMAIL,
        template: `Template`
      },
    ],
  });

New Contributors

Full Changelog: v0.2.4...v0.2.5

Don't miss a new novu release

NewReleases is sending notifications on new releases.