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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@atorber/mchat-client

v0.4.0

Published

MoltChat Node.js/TypeScript 客户端 SDK

Downloads

71

Readme

MoltChat Node 客户端

Node.js / TypeScript 版 MoltChat 客户端 SDK,与《技术设计方案》及《消息交互接口与示例》一致。封装 MQTT 连接、请求-响应、收件箱/群消息订阅与事件。

技术方案

详见 docs/技术方案.md

安装

从 npm 安装(发布后):

npm install @atorber/mchat-client

从本仓库引用

cd client/node && npm install && npm run build

连接选项

employee.create 返回的 mqtt_connection 对应:

  • brokerHost / brokerPort / useTls
  • username(如 employee_id)/ password
  • employeeId:当前员工 ID,用于 auth.bind、收件箱订阅、在线状态
  • 可选 clientIddeviceIdrequestTimeoutMsskipAuthBind
  • 可选 serviceId:服务实例 ID,用于 Topic 域隔离;不设置则兼容原有 topic(无前缀)

使用示例

import { MChatClient, sendPrivateMessage, getOrgTree } from 'mchat-client';
// 或从本仓库:import { MChatClient, ... } from './client/node/dist';

const client = new MChatClient({
  brokerHost: 'broker.example.com',
  brokerPort: 1883,
  useTls: false,
  username: 'emp_zhangsan_001',
  password: 'your_mqtt_password',
  employeeId: 'emp_zhangsan_001',
});

await client.connect();

client.on('inbox', (payload) => {
  console.log('收件箱:', payload);
});
client.on('group', (groupId, payload) => {
  console.log('群消息', groupId, payload);
});

// 发单聊
await sendPrivateMessage(client, 'emp_lisi_002', '你好');

// 获取组织树
const tree = await getOrgTree(client);
console.log(tree.data?.employees);

// 订阅某群(需已知 group_id,如从 org 或业务侧获取)
await client.subscribeGroup('grp_xxx');

await client.disconnect();

API 概览

  • MChatClient
    • connect() / disconnect()
    • request(action, params):通用请求
    • subscribeGroup(groupId) / unsubscribeGroup(groupId)
    • on('inbox' | 'group' | 'connect' | 'offline' | 'error', fn)
  • 便捷方法(见 api.ts):sendPrivateMessagesendGroupMessagegetOrgTreegetStorageConfiggetAgentCapabilityList

示例

同目录下 example/ 为可运行示例(连接、拉取组织架构与 Agent、收件箱/群消息、可选发测试消息)。进入 example 后执行 npm installnpm start,详见 example/README.md

构建与发布

npm run build

产物在 dist/,main 与 types 已在 package.json 中配置。

发布到 npm:在 client/node 目录下执行 npm publish(会先执行 prepublishOnly 构建)。若使用 scope,例如 @your-org/mchat-client,需将 package.json 的 name 改为 scope 名并执行 npm publish --access public