1.0.4 • Published 3 years ago
@moinai/notify v1.0.4
notify
统一消息推送服务模块
快速使用
安装
$ npm install @moinai/notify
使用
// 导入模块
const notify = require("@moinai/notify")
// 快捷发信
notify.mail.send({text:"hello world"})
功能介绍
- 发送邮件
- 发送
- 自定义发送
- 企业微信通知
- 发送
发送邮件
配置环境变量
MAIL_USERNAME = foo@bar.com
MAIL_PASSWORD = xxxxxxxxxxx
Demo
// 手动初始化快捷发信(可选)
notify.mail.config({
auth: {
user: "foo@bar.com",
pass: "xxxxxx..."
}
})
// 快捷发信
notify.mail.send({
to: "foo@bar.com", // 接受邮件的邮箱账号
subject: "...", // 邮件标题
text: "...", // 邮件内容
})
.then(data => {
console.log('data', data)
})
// 创建一个自定义client
let client = notify.mail.createClient({
auth: {
user: "foo@bar.com",
pass: "xxxxxx..."
}
})
// 利用创建的client发信
client.send({
to: "foo@bar.com", // 收件人邮箱账号
subject: "...", // 邮件标题
text: "...", // 邮件内容文本
html: "...", // 邮件内容富文本
})
.then(data => {
console.log('data', data)
})
企业微信通知
配置环境变量
# 渠道1
WEWORK_CHANNEL_CONTACT1 = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=__xxxxxx1'
# 渠道2
WEWORK_CHANNEL_CONTACT2 = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=__xxxxxx2'
Demo
// 发送企业微信通知
notify.wework.send({
channel: "WEWORK_CHANNEL_CONTACT1", // 选择发送渠道
text: "..." // 要发送的内容
})
.then(data => {
console.log('data', data.body)
})