Push All In One!支援Server 醬(以及Server 醬³)、自訂郵件、釘釘機器人、企業微信機器人、企業微信應用、pushplus、iGot 、Qmsg、息知、PushDeer、Discord、OneBot、Telegram 等多種推播方式。
Push All In One! Supports multiple push methods including Server Chan (and Server Chan³), custom email, DingTalk robot, WeChat Work robot, WeChat Work application, pushplus, iGot, Qmsg, XiZhi, PushDegramer, Discord, One, Qmsg, .
小提醒:出於安全考慮,所有推播方式請在服務端使用!請勿在客戶端(網頁端)使用!
Friendly Reminder: For security reasons, all push methods should be used on the server side ! Do not use them on the client side (web page) !
基於push-all-in-one 和hono 開發的雲端函數推送服務——push-all-in-cloud 。支援nodejs/docker/vercel 等部署方式,可一鍵部署到vercel 。
重大更新提示: push-all-in-one
v4 版本不相容v3 及以下低版本,請查看CHANGELOG 以了解變更。
BREAKING CHANGES : push-all-in-one
v4 version is not compatible with v3 and lower versions. Please refer to CHANGELOG for changes.
建議根據TypeScript 的類型提示進行修改。
Suggest modifying according to TypeScript's type prompts.
https://github.com/CaoMeiYouRen/push-all-in-one#readme
https://github.com/CaoMeiYouRen/push-all-in-one/tree/master/examples
npm i push-all-in-one -S
所有推送方式均實作了send(title: string, desp?: string, options?: any):
方法。
title
為消息标题
, desp
為消息描述
, options
為此推播方式的额外推送选项
,請參考各個推播管道的註解。
不知道如何設定配置?請前往push-all-in-cloud 設定產生器線上產生
push-all-in-one
和push-all-in-cloud
通用設定。
調用方式舉例:
import { ServerChanTurbo , ServerChanV3 , CustomEmail , Dingtalk , WechatRobot , WechatApp , PushPlus , IGot , Qmsg , XiZhi , PushDeer , Discord , OneBot , Telegram , runPushAllInOne } from 'push-all-in-one'
// 通过 runPushAllInOne 统一调用
runPushAllInOne ( '测试推送' , '测试推送' , {
type : 'ServerChanTurbo' ,
config : {
SERVER_CHAN_TURBO_SENDKEY : '' ,
} ,
option : {
} ,
} )
// Server酱·Turbo。官方文档:https://sct.ftqq.com/r/13172
const SCTKEY = 'SCTxxxxxxxxxxxxxxxxxxx'
const serverChanTurbo = new ServerChanTurbo ( {
SERVER_CHAN_TURBO_SENDKEY : SCTKEY ,
} )
serverChanTurbo . send ( '你好' , '你好,我很可爱 - Server酱·Turbo' , { } )
// 【推荐】Server酱³
// Server酱3。官方文档:https://sc3.ft07.com/doc
const SERVER_CHAN_V3_SENDKEY = 'sctpXXXXXXXXXXXXXXXXXXXXXXXX'
const serverChanV3 = new ServerChanV3 ( {
SERVER_CHAN_V3_SENDKEY ,
} )
serverChanV3 . send ( '你好' , '你好,我很可爱 - Server酱³' , { } )
// 【推荐】自定义邮件,基于 nodemailer 实现,官方文档: https://github.com/nodemailer/nodemailer
const customEmail = new CustomEmail ( {
EMAIL_TYPE : 'text' ,
EMAIL_TO_ADDRESS : '[email protected]' ,
EMAIL_AUTH_USER : '[email protected]' ,
EMAIL_AUTH_PASS : '123456' ,
EMAIL_HOST : 'smtp.qq.com' ,
EMAIL_PORT : 465 ,
} )
customEmail . send ( '你好' , '你好,我很可爱 - 自定义邮件' , { } )
// 【推荐】钉钉机器人。官方文档:https://developers.dingtalk.com/document/app/custom-robot-access
const DINGTALK_ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxx'
const DINGTALK_SECRET = 'SECxxxxxxxxxxxxxxxx'
const dingtalk = new Dingtalk ( {
DINGTALK_ACCESS_TOKEN ,
DINGTALK_SECRET ,
} )
dingtalk . send ( '你好' , '你好,我很可爱 - 钉钉机器人' , { msgtype : 'markdown' } )
// 企业微信群机器人。官方文档:https://developer.work.weixin.qq.com/document/path/91770
// 企业微信群机器人的使用需要两人以上加入企业,如果个人使用微信推送建议使用 企业微信应用+微信插件 推送。虽然需要配置的内容更多了,但是无需下载企业微信,网页端即可完成操作。
const WECHAT_ROBOT_KEY = 'xxxxxxxxxxxxxxxxxxxxxxx'
const wechatRobot = new WechatRobot ( {
WECHAT_ROBOT_KEY ,
} )
wechatRobot . send ( '你好,我很可爱- 企业微信群机器人' , '' , { msgtype : 'text' } )
// 【推荐】企业微信应用推送,官方文档:https://developer.work.weixin.qq.com/document/path/90664
// 微信插件 https://work.weixin.qq.com/wework_admin/frame#profile/wxPlugin
// 参数的介绍请参考:https://developer.work.weixin.qq.com/document/path/90665
// 支持 text 和 markdown 格式,但 markdown 格式仅可在企业微信中查看
const wechatApp = new WechatApp ( {
WECHAT_APP_CORPID : 'wwxxxxxxxxxxxxxxxxxxxx' ,
WECHAT_APP_AGENTID : 10001 , // 请更换为自己的 AGENTID
WECHAT_APP_SECRET : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ,
} )
wechatApp . send ( '你好,我很可爱 - 企业微信应用推送' , '' , {
msgtype : 'text' ,
touser : '@all' ,
} )
// pushplus 推送,官方文档:https://www.pushplus.plus/doc/
const PUSH_PLUS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxx'
const pushplus = new PushPlus ( { PUSH_PLUS_TOKEN } )
pushplus . send ( '你好' , '你好,我很可爱 - PushPlus' , {
template : 'html' ,
channel : 'wechat' ,
} )
// iGot 推送,官方文档:http://hellyw.com/#/
const I_GOT_KEY = 'xxxxxxxxxx'
const iGot = new IGot ( { I_GOT_KEY } )
iGot . send ( '你好' , '你好,我很可爱 - iGot' , {
url : 'https://github.com/CaoMeiYouRen/push-all-in-one' ,
topic : 'push-all-in-one' ,
} )
// Qmsg 酱 推送,官方文档:https://qmsg.zendee.cn
const QMSG_KEY = 'xxxxxxxxxxxx'
const qmsg = new Qmsg ( { QMSG_KEY } )
qmsg . send ( '你好,我很可爱 - Qmsg' , '' , {
type : 'send' ,
qq : '123456,654321' ,
} ) // msg:要推送的消息内容;qq:指定要接收消息的QQ号或者QQ群,多个以英文逗号分割,例如:12345,12346
// 息知 推送,官方文档:https://xz.qqoq.net/#/index
const XI_ZHI_KEY = 'xxxxxxxxxxxxx'
const xiZhi = new XiZhi ( { XI_ZHI_KEY } )
xiZhi . send ( '你好' , '你好,我很可爱 - XiZhi' )
// PushDeer 推送,官方文档:https://github.com/easychen/pushdeer
const PUSH_DEER_PUSH_KEY = 'xxxxxxxxxx'
const pushDeer = new PushDeer ( { PUSH_DEER_PUSH_KEY } )
pushDeer . send ( '你好' , '你好,我很可爱 - PushDeer' , {
type : 'markdown' ,
} )
// 【推荐】Discord Webhook 推送,官方文档:https://support.discord.com/hc/zh-tw/articles/228383668-%E4%BD%BF%E7%94%A8%E7%B6%B2%E7%B5%A1%E9%89%A4%E6%89%8B-Webhooks-
// [Recommended] Discord Webhook push. Official documentation: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
const DISCORD_WEBHOOK = 'https://discord.com/api/webhooks/xxxxxxxxxxxxxxxxxxxxxxxxxxx'
const DISCORD_USERNAME = 'My Bot'
const PROXY_URL = 'http://127.0.0.1:8101'
const discord = new Discord ( { DISCORD_WEBHOOK , PROXY_URL } )
// Discord 也支持以下方式添加代理地址
// Discord also supports adding proxy addresses in the following ways
// discord.proxyUrl = 'http://127.0.0.1:8101'
discord . send ( '你好,我很可爱 - Discord' , '' , {
username : DISCORD_USERNAME ,
} )
// 【推荐】Telegram Bot 推送。官方文档:https://core.telegram.org/bots/api#making-requests
// [Recommended] Telegram Bot push. Official documentation: https://core.telegram.org/bots/api#making-requests
const telegram = new Telegram ( {
TELEGRAM_BOT_TOKEN : '111111:xxxxxxxxxxxxxx' ,
TELEGRAM_CHAT_ID : 100000 ,
// PROXY_URL: 'http://127.0.0.1:8101',
} )
// Telegram 也支持以下方式添加代理地址
// Telegram also supports adding proxy addresses in the following ways
// telegram.proxyUrl = 'http://127.0.0.1:8101'
telegram . send ( '你好,我很可爱 - Telegram' , '' , {
disable_notification : true ,
} )
// OneBot 推送。官方文档:https://github.com/botuniverse/onebot-11
// 本项目实现的版本为 OneBot 11
// 在 mirai 环境下实现的插件版本可参考:https://github.com/yyuueexxiinngg/onebot-kotlin
const ONE_BOT_BASE_URL = 'http://127.0.0.1:5700'
const ONE_BOT_ACCESS_TOKEN = 'xxxxxxxxxxx'
const oneBot = new OneBot ( { ONE_BOT_BASE_URL , ONE_BOT_ACCESS_TOKEN } )
oneBot . send ( '你好,我很可爱 - OneBot 11' , '' , {
message_type : 'private' ,
user_id : 123456789 ,
} )
更多例子請參考examples
代理支援
環境變數 | 作用 | 例子 |
---|---|---|
NO_PROXY | 設定是否禁用代理 | true |
HTTP_PROXY | 設定http/https 代理 | http://127.0.0.1:8101 |
HTTPS_PROXY | 設定http/https 代理 | http://127.0.0.1:8101 |
SOCKS_PROXY | 透過socks/socks5 協議設定http/https 代理 | socks://127.0.0.1:8100 |
本專案透過環境變數來支援請求代理
// 在 nodejs 项目中可通过直接设置环境变量来设置代理
process . env . HTTP_PROXY = 'http://127.0.0.1:8101' // 当请求是 http/https 的时候走 HTTP_PROXY
process . env . HTTPS_PROXY = 'http://127.0.0.1:8101' // 当请求是 http/https 的时候走 HTTPS_PROXY,HTTPS_PROXY 优先
process . env . SOCKS_PROXY = 'socks://127.0.0.1:8100' // 当 HTTP_PROXY 设置时走 SOCKS_PROXY
// process.env.NO_PROXY = true // 设置 NO_PROXY 可禁用代理
在命令列中可手動設定環境變數
set HTTP_PROXY= ' http://127.0.0.1:8101 ' # Windows
export HTTP_PROXY= ' http://127.0.0.1:8101 ' # Linux
cross-env HTTP_PROXY= ' http://127.0.0.1:8101 ' # 通过 cross-env 这个包来跨平台
本專案採用TypeScript 開發,使用tsup 打包,可完美實現類型提示和搖樹最佳化,對於未使用的模組,會在編譯階段移除。
npm run dev
本專案使用debug
這個套件來debug ,如果要開啟偵錯則設定環境變數為DEBUG=push:*
即可,例如
cross-env DEBUG=push: * NODE_ENV=development ts-node-dev test/index.test.ts # 因为一些原因该文件未上传,可自行编写测试用例
npm run build
npm run lint
npm run commit
CaoMeiYouRen
歡迎貢獻、提問或提出新功能!
如有問題請查看issues page.
貢獻或提出新功能可以查看contributing guide.
Welcome to contribute, ask questions or propose new features!
If you have any questions, please check the issues 頁.
For contributions or new feature proposals, please refer to the contributing guide.
如果覺得這個專案有用的話請給一顆️,非常感謝。
If you find this project useful, please give it a ️. Thank you very much.
Copyright © 2022 CaoMeiYouRen.
This project is MIT licensed.
This README was generated with ❤️ by cmyr-template-cli