npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dingdingbot

v1.0.4

Published

钉钉机器人typescript版本

Downloads

10

Readme

一、钉钉自定义机器人介绍

钉钉机器人是钉钉群的一个高级扩展功能,但使用起来却非常简单,只需要注册一个钉钉账号,就可以将第三方服务信息聚合到钉钉群中,实现信息的自动同步。

常见的使用场景:

1、聚合Github、Gitlab等源码管理服务,实现源码更新同步;

2、聚合Trello、JIRA等项目协调服务,实现项目信息同步;

3、机器人支持Webhook自定义接入,就可以实现更多可能性,例如:将运维报警、自动化测试结果报告、工作&生活日程安排(上班打卡、下班吃饭、健身、读书、生日、纪念日...)的提醒;

目前自定义机器人支持文本(text)、链接(link)、markdown三种消息格式,五种消息类型,详细信息请参考自定义机器人官方文档

二、安装使用

这么好用的功能,只要在钉钉群中添加机器人,得到Webhoo地址即可。接下来,我们先在命令行终端一睹为快吧:

curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx' \
   -H 'Content-Type: application/json' \
   -d '
  {"msgtype": "text",
    "text": {
        "content": "我就是我, 是不一样的烟火"
     }
  }'
npm install dingdingbot

支持功能如下

  • 支持Text消息;
  • 支持Link消息;
  • 支持Markdown消息;
  • 支持ActionCard消息;
  • 支持image表情消息;
  • 支持钉钉官方消息发送频率限制限制:每个机器人每分钟最多发送20条;
  • 支持最新版钉钉机器人加密设置密钥验证;

Text文件类型发送

DingDingBot机器人配置初始化

const { DingDingBot } = require('dingdingbot')

// 不携带加密token
const bot = new DingDingBot('https://oapi.dingtalk.com/robot/send?access_token=eed4cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
// 携带加密token
const bot = new DingDingBot('https://oapi.dingtalk.com/robot/send?access_token=eed4cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'SECxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

三、各消息类型使用示例

Text消息

image-20220615140552707

bot.sendText({ msg: 'Hello World!' }).then(r => console.log(r))

image-20220615140733204

// @所有人
bot.sendText({ msg: 'Hello World!', isAtAll: true }).then(r => console.log(r))

image-20220615141135608

// Text消息之@指定用户atMobiles: ['188xxxxx', '187xxxxx'] 改写手机号
bot.sendText({
  msg: 'Hello World!',
  isAtAll: false,
  atMobiles: ['188xxxxx', '187xxxxx'],
  atDingTalkIds: ['userid1', 'userid2']
}).then(r => console.log(r))

image-20220615141257175

Image表情消息

// Image表情消息
const catImageUrl = 'https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/18d8bc3eb13533facf73c7a1a9d3fd1f40345b73.jpg'
bot.sendImage(catImageUrl).then(r => console.log(r)).catch(e => console.log(e))

image-20220615141433188

Link消息

// Link消息
bot.sendLink({
  text: 'Hello World!',
  title: '万万没想到!',
  picUrl: 'https://pic.dmjnb.com/pic/cef5dd8fb7aaabb8bb116bb55f270ba9?imageMogr2/thumbnail/x380/quality/90!',
  messageUrl: 'https://www.baidu.com'
}).then(r => console.log(r)).catch(e => console.log(e))

image-20220615141545661

Markdown消息

// Markdown消息@所有人
bot.sendMarkdown({
    title: '漢洲天機',
    text: '#### 杭州天气 @150XXXXXXXX \n > 9度,西北风1级,空气良89,相对温度73%\n > ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n > ###### 10点20分发布 [天气](https://www.dingtalk.com) \n',
    isAtAll: true
  }
).then(r => console.log(r)).catch(e => console.log(e))

// Markdown消息
bot.sendMarkdown({
    title: '漢洲天機',
    text: '#### 杭州天气 @150XXXXXXXX \n > 9度,西北风1级,空气良89,相对温度73%\n > ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n > ###### 10点20分发布 [天气](https://www.dingtalk.com) \n',
    isAtAll: false
  }
).then(r => console.log(r)).catch(e => console.log(e))

// @某个人
bot.sendMarkdown({
    title: '漢洲天機',
    text: '#### 漢洲天機 @18727792911 \n > 9度,西北风1级,空气良89,相对温度73%\n > ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n > ###### 10点20分发布 [天气](https://www.dingtalk.com) \n',
    atMobiles: ['18871535971', ['18727792911'], ['21312321123']]
  }
).then(r => console.log(r)).catch(e => console.log(e))

image-20220615142007010

FeedCard消息

// FeedCard消息
const card1 = CardItem('氧气美女',
  'https://www.dingtalk.com/',
  'https://pic.dmjnb.com/pic/cef5dd8fb7aaabb8bb116bb55f270ba9?imageMogr2/thumbnail/x380/quality/90'
)
const card2 = CardItem('氧气美女',
  'https://www.dingtalk.com/',
  'https://pic.dmjnb.com/pic/cef5dd8fb7aaabb8bb116bb55f270ba9?imageMogr2/thumbnail/x380/quality/90'
)
const card3 = CardItem('氧气美女',
  'https://www.dingtalk.com/',
  'https://pic.dmjnb.com/pic/cef5dd8fb7aaabb8bb116bb55f270ba9?imageMogr2/thumbnail/x380/quality/90'
)
bot.sendFeedCard(
  [card1, card2, card3]
).then(r => console.log(r)).catch(e => console.log(e))

image-20220615142215447

ActionCard消息

// ActionCard消息
const btns2 = [ActionCardItem('支持1+1', 'https://www.dingtalk.com/'), ActionCardItem('反对2+2', 'https://www.dingtalk.com/')]
bot.sendActionCard({
  headers: ['投票'],
  btns: btns2,
  text: `![选择](${catImageUrl}) \n### 故事是这样子的...`
}).then(r => console.log(r)).catch(e => console.log(e))

image-20220615142404641

// 选项卡换方向
d.sendActionCard({
  headers: ['投票'],
  btns: btns2,
  btnOrientation: '1',
  text: `![选择](${catImageUrl}) \n### 故事是这样子的...`
}).then(r => console.log(r)).catch(e => console.log(e))