# notification **Repository Path**: ksdhy/notification ## Basic Information - **Project Name**: notification - **Description**: 消息通知,目前支持Bark、Email,后续会扩展其他通知形式 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-31 - **Last Updated**: 2025-10-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Notification Service (Node.js) 支持多种通知渠道:Bark 与 Email(SMTP)。通过环境变量配置,易于扩展更多渠道。 ### 安装 ```bash npm install ``` ### 配置 根据config自行配置env 关键环境变量: - `BARK_BASE_URL`、`BARK_DEVICE_KEYS`(逗号分隔)等 - `SMTP_HOST`、`SMTP_PORT`、`SMTP_SECURE`、`SMTP_USER`、`SMTP_PASS`、`EMAIL_FROM` ### 使用示例 ```bash npm run send:example ``` 或在代码中: ```js const { NotificationService } = require('./src'); const svc = new NotificationService(); await svc.send( { title: '标题', body: '内容' }, { channels: ['bark', 'email'], perChannel: { email: { to: 'a@b.com' } } } ); ``` ### 扩展渠道 新增渠道时实现 `send(message)` 方法并在 `NotificationService` 注册即可。 ### HTTP 服务(Express) 启动服务(默认 3002 端口): ```bash npm start ``` POST `http://localhost:3002/notify` Request JSON: ```json { "type": "all | bark | email", "title": "通知标题", "content": "通知内容", "barkDeviceKeys": "key1,key2" , "emailTo": "a@b.com,b@c.com" } ``` - `type`: 发送渠道(默认 `all`)。 - `title` 与 `content`: 必填。 - `barkDeviceKeys`: 可选(数组或逗号分隔字符串)。未提供时使用环境变量 `BARK_DEVICE_KEYS`。 - `emailTo`: 可选(数组或逗号分隔字符串)。未提供时示例会尝试使用 `DEMO_EMAIL_TO`。 响应: ```json { "ok": true, "results": [ { "channel": "bark", "ok": true }, { "channel": "email", "ok": true } ] } ``` 失败时: ```json { "ok": false, "message": "...", "results": [ { "channel": "bark", "ok": false, "error": "..." } ] } ```