Notifire通知管理简化

联合创作 · 2023-10-01 04:02

Notifire 是一个开源库,用于使用单个 API 管理多渠道事务通知。为 Node.js 构建的简单易用的 OCL,易于使用的模板,不再有供应商锁定,统一的 API。


目标是简化通知并为开发人员提供工具以在系统与其用户之间创建有意义的通信。


特性:



  • 适用于所有消息传递提供商的单一 API(电子邮件、短信、推送、直接)

  • 轻松管理多个渠道的通知

  • 配备用于高级布局和设计的模板引擎

  • 缺失变量的内置保护

  • 易于设置和集成

  • 用 TypeScript 编写,具有可预测的静态类型。

  • 社区驱动



import { Notifire, ChannelTypeEnum } from '@notifire/core';
import { SendgridEmailProvider } from '@notifire/sendgrid';

const notifire = new Notifire();

await notifire.registerProvider(
new SendgridEmailProvider({
apiKey: process.env.SENDGRID_API_KEY,
from: 'sender@mail.com'
})
);

const passwordResetTemplate = await notifire.registerTemplate({
id: 'password-reset',
messages: [
{
subject: 'Your password reset request',
channel: ChannelTypeEnum.EMAIL,
template: `
Hi {{firstName}}!

To reset your password click <a href="{{resetLink}}">here.</a>

{{#if organization}}
<img src="{{organization.logo}}" />
{{/if}}
`
},
]
});

await notifire.trigger('<REPLACE_WITH_EVENT_NAME>', {
$user_id: "<USER IDENTIFIER>",
$email: "test@email.com",
firstName: "John",
lastName: "Doe",
organization: {
logo: 'https://evilcorp.com/logo.png'
}
});
浏览 27
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报