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

@zhengxs/dingtalk-sdk-js

v0.0.1-beta.1

Published

[![Typescript](https://img.shields.io/badge/lang-typescript-informational?style=flat-square)](https://www.typescriptlang.org)[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/pretti

Downloads

1

Readme

@zhengxs/dingtalk-sdk-js

Typescriptcode style: prettiernpm packagenpm downloadsLicense

当前状态:Alpha

非官方 JS-SDK,请勿在生产中使用。

文档

安装

# With NPM
$ npm i -S @zhengxs/dingtalk-sdk-js

# With Yarn
$ yarn add @zhengxs/dingtalk-sdk-js

# With PNPM
$ pnpm add @zhengxs/dingtalk-sdk-js

使用

企业机器人开发

import { DingtalkClient, StreamClient } from '@zhengxs/dingtalk-sdk-js';

const client = new DingtalkClient({
  clientId: 'My Client ID',
  clientSecret: 'My Client Secret',
});

// 订阅消息
const connection = new StreamClient(client);

// 监听机器人消息
connection.onImMessage(function (message) {
  console.log('接收到的消息', message.data);

  // 回复消息给当前发送者
  message.reply('hello,world');
});

connection.connect();

链接

自定义机器人开发

如果传递 secret 参数,会自动对 URL 进行签名

import { CustomizeWebhook } from '@zhengxs/dingtalk-sdk-js';

const webhook = new CustomizeWebhook({
  token: 'webhook token',
  secret: 'webhook secret',
});

webhook.say('hello,world');

详见 自定义机器人接入

获取企业内部应用的身份凭证

如果凭证过期,内部会自动获取最新的可用凭证,无需外部处理。

import { SessionCredentials } from '@zhengxs/dingtalk-sdk-js';

const session = new SessionCredentials({
  clientId: 'My Client ID',
  clientSecret: 'My Client Secret',
});

async function main() {
  const token = await session.getAccessToken();

  console.log(token);
}

main();

详见 获取企业内部应用的身份凭证

发送互动卡片

import { DingtalkClient, StreamClient } from '@zhengxs/dingtalk-sdk-js';

const client = new DingtalkClient({
  clientId: process.env.DINGTALK_CLIENT_ID,
  clientSecret: process.env.DINGTALK_CLIENT_SECRET,
});

const connection = new StreamClient(client);

connection.onImMessage(async message => {
  // 发送互动卡片
  const data = await client.card.instances.send({
    outTrackId: 'Your out trackId',
    cardTemplateId: 'Your card templateId',
    openConversationId: message.conversationId,
    receiverUserIdList: [message.talker.staffId],
    conversationType: message.conversationType === '2' ? 1 : 0, // 互动卡片和消息卡片的聊天类型值不一致
    chatBotId: message.robot.id, // 根据做了判断,如果是私聊,会直接删除机器人ID
    robotCode: message.robot.code, // 根据做了判断,如果是私聊,会直接删除机器人编码
    cardData: {
      cardParamMap: {},
    },
    // 其他参数...
  });

  console.log(data);
});

connection.connect();

参考

License

MIT