@cvo/plugin-notification
v0.0.0
Published
Notification plugin for CVO Framework
Readme
@cvo/plugin-notification
Unified notification center for CVO Framework. Send messages via Email (SMTP), Feishu, DingTalk, and more with a single API.
🚀 Features
- Unified API: A single
send()orNotify.send()method to rule them all. - Multi-Driver Support: Built-in support for Email, Feishu Webhooks, DingTalk Webhooks, and Console Logs.
- Broadcast Support: Easily send messages across all configured channels at once.
- Simple Integration: Accessible via
useNotification()hook or the staticNotifyhelper.
🛠 Configuration
Configure your notification channels in cvo.config.ts:
import { defineConfig } from '@cvo/core';
import { NotificationPlugin } from '@cvo/plugin-notification';
export default defineConfig({
plugins: [
new NotificationPlugin({
channels: {
email: {
host: 'smtp.example.com',
port: 465,
auth: { user: '[email protected]', pass: 'secret' },
from: 'System <[email protected]>'
},
feishu: {
webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx'
},
log: true // Enable console logging for development
}
})
]
});🧠 Usage
Minimalistic Approach (Notify Helper)
Use the Notify static class for quick notifications. It automatically routes to all available channels if no specific channel is provided.
import { Notify } from '@cvo/plugin-notification';
// Send email to a specific user
await Notify.send('[email protected]', 'Your verification code is 123456');
// Send to a specific channel
await Notify.send('admin@system', 'Server disk space low', { channel: 'log' });Using the Hook (useNotification)
The hook provides full access to the plugin instance. Note the parameter order for the send method: (to, message, channel, options).
import { useNotification } from '@cvo/server';
export async function alertAdmin() {
const notification = useNotification();
// Method signature: send(to, message, channelName, options?)
await notification.send(
'[email protected]',
'Database backup failed!',
'email',
{ subject: 'CRITICAL: Backup Failure' }
);
// Broadcast to ALL configured channels (Email, Feishu, etc.)
await notification.broadcast('System upgrade scheduled for 10 PM tonight.');
}🛠 Built-in Drivers
- Email (
email): SMTP-based delivery usingnodemailer. - Log (
log): Outputs to the console/audit logs. Recommended for development. - Webhook (
feishu,dingtalk): HTTP POST to platform-specific webhooks.
🛠 Custom Channels
You can extend the notification center by implementing the NotificationChannel interface.
