通知
学习如何在 MkSaaS 中设置和使用通知
MkSaaS 支持在用户成功完成支付时发送通知,这允许您的团队在工具中接收实时订单提醒。
目前支持 Discord 和飞书两种通知渠道,并且易于扩展添加更多通知渠道。
设置
启用通知渠道
在 src/config/website.tsx 中启用通知功能,并配置接收消息的通知渠道:
export const websiteConfig: WebsiteConfig = {
// ...other config
notification: {
enable: true,
provider: 'discord', // or 'feishu'
},
// ...other config
}配置 Webhook URL
根据选择的通知渠道,配置对应的 Webhook URL:
- 进入到 Discord 服务器并打开想要接收通知的频道
- 点击齿轮图标打开
Channel Settings - 选择
Integrations>Webhooks>New Webhook - 为 Webhook 设置名称和头像(可选)
- 复制
Webhook URL并添加到环境变量文件中:
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."- 进入到飞书群聊
- 点击群名称 >
Group Settings>Bot Management - 添加新的
Custom Bot并启用Webhooks - 复制生成的
Webhook URL并添加到环境变量文件中:
FEISHU_WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/..."如果您正在设置环境,现在可以回到环境配置文档并继续。本文档的其余部分可以稍后阅读。
环境配置
设置环境变量
通知消息示例
Discord 消息
Discord 通知作为带有绿色和结构化字段的消息发送,便于阅读。

飞书消息
飞书通知作为纯文本消息发送,所有购买信息清晰明了。

扩展新的通知渠道
MkSaaS 支持扩展新的通知渠道:
- 在
src/notification目录中创建新文件(例如slack.ts)。 - 实现通知函数:
export async function sendMessageToSlack(
sessionId: string,
customerId: string,
userName: string,
amount: number
): Promise<void> {
try {
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
if (!webhookUrl) {
console.warn('SLACK_WEBHOOK_URL is not set, skipping Slack notification');
return;
}
// Your Slack message implementation
await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: `🎉 New Purchase\nUsername: ${userName}\nAmount: $${amount.toFixed(2)}`,
}),
});
} catch (error) {
console.error('Failed to send Slack notification:', error);
}
}- 在
notification.ts中导入并调用此函数:
import { sendMessageToSlack } from './slack';
// 添加到 sendNotification 函数中
await sendMessageToSlack(sessionId, customerId, userName, amount);
MkSaaS文档