# @moinai/notify

> 通知模块

Latest version **1.0.4** (published 2021-08-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install @moinai/notify
pnpm add @moinai/notify
yarn add @moinai/notify
bun add @moinai/notify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-08-03 |
| First published | 2021-06-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 (+22 in 1 direct dependencies) |
| Install scripts | no |
| Author | 邬昊轩 |
| Maintainers | moinai |

## Links

- npm: https://www.npmjs.com/package/@moinai/notify
- npm.io page: https://npm.io/package/@moinai/notify

## Dependencies (2)

- [nodemailer](https://npm.io/package/nodemailer.md) ^6.6.1
- [superagent](https://npm.io/package/superagent.md) ^6.1.0

## Recent versions

- 1.0.4 (latest) — 2021-08-03
- 1.0.3 — 2021-06-29
- 1.0.2 — 2021-06-28
- 1.1.0 — 2021-06-28
- 1.0.0 — 2021-06-28

## README

# notify
统一消息推送服务模块

## 快速使用

安装
```bash
$ npm install @moinai/notify
```

使用
```js
// 导入模块
const notify = require("@moinai/notify")

// 快捷发信
notify.mail.send({text:"hello world"})
```

## 功能介绍
- 发送邮件
    1. 发送
    2. 自定义发送
- 企业微信通知
    1. 发送

## 发送邮件

配置环境变量
```bash
MAIL_USERNAME = foo@bar.com
MAIL_PASSWORD = xxxxxxxxxxx
```
Demo
```js
// 手动初始化快捷发信（可选）
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)
})

```

## 企业微信通知
配置环境变量
```bash
# 渠道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
```js
// 发送企业微信通知
notify.wework.send({
    channel: "WEWORK_CHANNEL_CONTACT1", // 选择发送渠道
    text: "..."                         // 要发送的内容
})
.then(data => {
    console.log('data', data.body)
})
```

---
_Source: https://npm.io/package/@moinai/notify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
