惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
PCI Perspectives
PCI Perspectives
Webroot Blog
Webroot Blog
罗磊的独立博客
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Last Week in AI
Last Week in AI
美团技术团队
Help Net Security
Help Net Security
The Hacker News
The Hacker News
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
The Register - Security
The Register - Security
IT之家
IT之家
WordPress大学
WordPress大学
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Help Net Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
NISL@THU
NISL@THU
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
B
Blog
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
S
Security Affairs
小众软件
小众软件
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
A
Arctic Wolf
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence

HCLonely Blog

HCLonely Blog - 让OpenWrt控制台进入赛博空间:luci-theme-cyberpunk HCLonely Blog - Artitalk V4: 从Leancloud迁移至Vercel HCLonely Blog - 记一次hexo-bilibili-bangumi分时函数渲染优化 HCLonely Blog - IP签名图片生成服务 HCLonely Blog - 树莓派搭建私有在线PS网站 HCLonely Blog - 将 Node.js 项目打包为一个可执行文件 HCLonely Blog - 哔哩哔哩硬核会员搜题脚本 HCLonely Blog - 在静态网站上实现浏览记录功能 HCLonely Blog - 在线答题搜答案脚本 HCLonely Blog - 青年大学习安卓跳过方法 HCLonely Blog - 公主连结 Re:Dive 中文输入法词库 HCLonely Blog - 基于 NodeJs 的 live2d 后端 Api 服务器 HCLonely Blog - 百度分析和谷歌分析适配 pjax HCLonely Blog - hexo-calendar 活动日历插件 HCLonely Blog - Git 免密、免 SSH 进行 push & pull HCLonely Blog - 一款基于 webstack 的 hexo 主题 HCLonely Blog - 使用 cron-job 解决 LeanCloud 因流控原因自动唤醒失败的问题 HCLonely Blog - Valine 添加验证码、博主标签及评论微信、QQ 通知 HCLonely Blog - 使用 Cloud Studio 在线搭建、编辑、部署 Hexo HCLonely Blog - 给你的网页添加一个 moc3 格式的 Live2d 模型 HCLonely Blog - Hexo-tag-steamgame 插件 HCLonely Blog - Hexo-online-server 在线编辑发布文章插件 HCLonely Blog - Hexo 博客美化
HCLonely Blog - 统一推送服务Nodejs API
博主:HCLonely · 2022-12-21 · via HCLonely Blog

本文最后更新于天前,内容可能已不再适用!

介绍

注意:此模块仅作推送使用,不可交互 !!!

统一化推送服务Nodejs API. 已支持钉钉, Discord, 邮件, 飞书, PushDeer, PushPlus, QQ, QQ 频道机器人, Server 酱, Showdoc Push, Telegram Bot, 企业微信群机器人, 息知, WxPusher, NowPush, iGot, Chanify, Bark, Push, Slack, Pushback, Zulip, RocketChat, Gitter等平台.

已支持平台

安装

npm install all-pusher-api -S

使用

Example

多平台推送

const { PushApi } = require('all-pusher-api'); // 多平台同时推送

(async () => {
  console.log((await new PushApi([
    {
      name: 'ServerChanTurbo',
      config: {
        key: {
          token: '******'
        }
      }
    },
    {
      name: 'PushDeer',
      config: {
        key: {
          token: '******'
        }
      }
    },
    {
      name: 'WxPusher',
      config: {
        key: {
          token: '******',
          uids: ['******']
        }
      }
    }
  ])
    .send({ message: '测试文本' })).map((e) => (e.result.status >= 200 && e.result.status < 300) ? `${e.name} 测试成功` : e));
})();

单平台推送

(async () => {
  // Example 1
  const { PushApi } = require('all-pusher-api'); // 多平台同时推送

  const result = await new PushApi([
    {
      name: 'ServerChanTurbo',
      config: {
        key: {
          token: '******'
        }
      }
    }
  ])
    .send({ message: '测试文本' });
  console.log(result.map((e) => (e.result.status >= 200 && e.result.status < 300) ? `${e.name} 测试成功` : e));

  // Example 2
  const { WxPusher } = require('all-pusher-api/dist/WxPusher'); // 单平台推送可选

  const wxPusherResult = await new WxPusher({
    token: '******',
    uids: ['******']
  })
    .send({ message: '测试文本' });
  console.log(wxPusherResult);
})();

extraOptions

(async () => {
  const { DingTalk } = require('all-pusher-api/dist/DingTalk');

  const result = await new DingTalk({
    key: {
      token: '******',
      secret: '******'
    }
  })
    .send({
      message: '这条消息@了所有人',
      extraOptions: {
        isAtAll: true
      }
    });
  console.log(result);
})();

customOptions

这里以钉钉为例

(async () => {
  const { DingTalk } = require('all-pusher-api/dist/DingTalk');

  const result = await new DingTalk({
    key: {
      token: '******',
      secret: '******'
    }
  })
    .send({
      customOptions: {
        "msgtype": "actionCard",
        "actionCard": {
          "title": "我 20 年前想打造一间苹果咖啡厅, 而它正是 Apple Store 的前身",
          "text": "![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化, 而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
          "btnOrientation": "0",
          "btns": [
            {
                "title": "内容不错",
                "actionURL": "https://www.dingtalk.com/"
            },
            {
                "title": "不感兴趣",
                "actionURL": "https://www.dingtalk.com/"
            }
          ]
        }
      }
    });
  console.log(result);
})();

自定义接口

(async () => {
  const { Custom } = require('all-pusher-api/dist/Custom'); // 自定义接口只能通过此方法引入
  const { createHmac } = require('crypto');
 const sign = () => {
    const timestamp = new Date().getTime();
    const secret = '******';
    const stringToSign = `${timestamp}\n${secret}`;
    const hash = createHmac('sha256', secret)
      .update(stringToSign, 'utf8')
      .digest();
    return `timestamp=${timestamp}&sign=${encodeURIComponent(hash.toString('base64'))}`;
  };
  console.log(await new Custom({
    url: `https://oapi.dingtalk.com/robot/send?access_token=******&${sign()}`,
    success: {
      key: 'responseData.errcode',
      value: 0
    }
  }).send({
    msgtype: 'text',
    text: {
      content: '测试文本'
    }
  }));
  /* 返回值
  {
    status: 200,
    statusText: 'Success',
    extraMessage: <AxiosResponse>
  }
  */
});

参数

pusherConfig

这部分写的比较乱,建议配合参数生成器使用!

const pusher = new WxPusher(pusherConfig);

参数类型默认值说明
tokenstringnull大部分平台的授权token, 如果有授权信息有多个, 请使用key
baseUrlstringnull对于部分支持搭建服务端的平台, 如果使用自建服务端, 需配置此选项
webhookstringnullDiscord,企业微信机器人,RocketChatGoogleChat的 webhook 地址, 该平台请使用webhook而不是token
userIdstringnullPushback平台的 User_id
chat_idstringnullTelegram平台的 chat_id
emailstringnullZulip平台的 bot email
domainstringnullZulip平台的 domain
toArray<number\|string>nullZulip平台的发送对象
roomIdstringnullGitter平台发送对象的 roomid
baseUrlstringnullgo-cqhttp 的http通信地址, 以http://https://开头
user_idnumbernull使用 go-cqhttp 推送时的目标 QQ 号, 此参数与group_id,channel_id二选一
group_idnumbernull使用 go-cqhttp 推送时的目标群号, 此参数与user_id,channel_id二选一
channel_idstringnull使用 go-cqhttp 推送时的目标频道ID, 此参数与user_id,group_id二选一, 且必须与guild_id同时存在
guild_idstringnull使用 go-cqhttp 推送时的目标子频道ID, 此参数必须与channel_id同时存在
corpidstringnull企业微信群机器人的corpid
agentidstringnull企业微信群机器人的agentid
secretstringnull钉钉、飞书加签的密钥[可选]/企业微信群机器人的secret
touserstringnull企业微信群机器人指定接收消息的成员, 也可在sendOptions中配置
uidsArray<string>nullWxPusher 发送目标的 UID, 也可在sendOptions中配置
topicIdsArray<number>nullWxPusher 发送目标的 topicId, 也可在sendOptions中配置
appIDstringnullQQ频道机器人的 ID, 使用QQ频道推送时此选项为必选
tokenstringnullQQ频道机器人的 token, 使用QQ频道推送时此选项为必选
sandboxbooleanfalse使用QQ频道推送时是否启用沙箱, 可选
channelIDstringnullQQ频道的子频道 ID, 使用QQ频道推送时此选项为必选
userstringnullPushover 的 user key, 使用 Pushover 推送时此选项为必选
keyobjectnull以上参数都可以放到key中,示例
-key.hoststringnull邮件发送服务器地址, 使用邮件推送时此选项为必选
-key.portnumbernull邮件发送服务器端口, 使用邮件推送时此选项为必选
-key.securebooleanfalse邮件发送服务器是否启用TLS/SSL, 可选
-key.authobjectnull邮件发送服务器的验证信息, 使用邮件推送时此选项为必选
-key.auth.userstringnull邮件发送服务器的用户名, 使用邮件推送时此选项为必选
-key.auth.passstringnull邮件发送服务器的密码, 使用邮件推送时此选项为必选
proxyobjectnull代理配置, 可选, 部分支持
-proxy.enablebooleanfalse是否启用代理
-proxy.protocolstring'http'代理协议
-proxy.hoststringnull代理主机地址
-proxy.portnumbernull代理端口
-proxy.usernamestringnull代理用户名
-proxy.passwordstringnull代理密码

CustomConfig

自定义接口

const customPusher = new Custom(CustomConfig);

参数类型默认值说明
urlstringnull请求链接, 必需
methodstring'POST'请求方式, 可选
contentTypestring'application/json'发送的数据类型, 等同于hreders['Content-type']
headersAxiosRequestHeadersnull请求头, 可选
successobjectnull推送成功的判断方式, 必需
-success.keystringnull请看示例
-success.valueanynull请看示例
keyobjectnull以上参数都可以放到key中
proxyobjectnull代理配置, 同上

pushersConfig

const pushers = new PushApi(pushersConfig);

const pushersConfig: Array<{
  name: string,
  config: pusherConfig
}>

sendOptions

const result = await pusher.send(sendOptions);

参数类型默认值说明
messagestringnull推送的消息内容,messagecustomOptions至少要有一个
titlestringnull部分平台支持消息标题, 不填则自动提取message第一行的前10个字符
typestring'text'仅支持text,markdown,html. 具体平台支持情况请查看支持的消息类型
extraOptionsobjectnull附加内容, 此对象中的内容会附加到请求体中,示例
customOptionsobjectnull自定义请求内容, 推送时会POSTcustomOptions,示例

customSendOptions

const result = await customPusher.send(customSendOptions);

customSendOptions会直接作为请求体发送, 具体请查看示例.

pushersSendConfig

const results = await pushers.send(pushersSendConfig);

const pushersSendConfig: Array<{
  name: string
  config: pushersSendConfig
}>

返回值

result

constresult= await pusher.send(sendOptions);

参数类型默认值说明
statusnumbernull状态码
statusTextstringnull状态说明文本
extraMessageAxiosResponseErrornull

results

constresults= await pushers.send(pushersSendConfig);

const results: Array<{
  name: string
  result: result
}>

支持的消息类型

所有平台支持均纯文本(text)格式消息, 大部分支持markdown格式消息, 部分支持html格式消息

markdown*为支持html格式不支持markdown格式消息时自动将markdown转换为html格式

other为部分平台支持特殊格式的消息, 可通过customOptions传入参数, 具体参数请查看相应平台的文档

  • Showdoc:text
  • Pushover:text
  • QQ(go-cqhttp):text,other
  • Qmsg:text,other
  • Discord:text,other
  • 飞书:text,other
  • NowPush:text,other
  • Chanify:text,other
  • Bark:text,other
  • Server酱Turbo:text,markdown
  • 息知:text,markdown
  • PushDeer:text,markdown,other
  • QQ频道:text,markdown,other
  • 企业微信:text,markdown,other
  • 企业微信群机器人:text,markdown,other
  • 钉钉:text,markdown,other
  • TelegramBot:text,markdown,html
  • 邮件:text,markdown*,html
  • PushPlus:text,markdown*,html
  • WxPusher:text,markdown*,html

状态码

  • 0-Missing Parameter: ***: 缺少必要参数
  • 10-Missing Options: 缺少发送消息配置
  • 11-Unknown Error: 未知错误
  • 200-Success: 推送成功
  • 201-Waiting: 待审核
  • 100-Error: 请求发送成功, 服务器返回错误信息
  • 101-No Response Data: 请求发送成功, 但没有接收到服务器返回的数据
  • 102-Request Error: 请求发送失败, 一般是网络问题
  • 103-Options Format Error: 参数格式错误
  • 104-Get "***" Failed: 获取参数失败
  • 140-Check Sign Failed: 签名校检失败