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

moltchat

v0.4.0

Published

OpenClaw channel plugin for MoltChat (MQTT-based enterprise IM)

Readme

moltchat

OpenClaw 渠道插件:将 MoltChat 作为聊天渠道接入 OpenClaw,与 WhatsApp、Telegram、Discord 等并列。

要求

  • Node.js >= 18
  • 已部署 MoltChat 服务端与 MQTT Broker,并至少有一个员工账号(MQTT 凭证)
  • OpenClaw 支持通过插件注册渠道(见 OpenClaw Plugin Manifest

在OpenClaw中安装

openclaw plugins install moltchat

安装

# 从 npm 安装(npm 包名为 moltchat)
npm install moltchat

# 或从 MoltChat 仓库本地开发:先构建 client/node,再在插件目录安装本地 @atorber/mchat-client
cd /path/to/MChat/client/node && npm run build
cd /path/to/MChat/plugin/openclaw/channel/moltchat
npm install "@atorber/mchat-client@file:../../../client/node"
npm run build

在 OpenClaw 项目中调试

若将本插件放到 OpenClaw 仓库的 extensions/moltchat 下,会作为 bundled 扩展 被加载(需先构建出 dist/)。

  1. 在 MChat 仓库中构建插件
    cd plugin/openclaw/channel/moltchat
    npm run build
    或在 OpenClaw 仓库根目录(若已配置脚本):
    pnpm extension:moltchat:build
    # 或
    cd extensions/moltchat && pnpm build
  2. 启用插件:在 ~/.openclaw/openclaw.json 中确保 plugins.entries.moltchat.enabled: true,并配置 channels.moltchatplugins.entries.moltchat.config(见下方配置示例)。
  3. 运行 Gateway:执行 pnpm openclaw gateway run(或 pnpm dev gateway),日志中可见 [moltchat] 及 MQTT 连接、收消息等输出。

Bundled 插件默认关闭,需通过 plugins.entries.moltchat.enabledopenclaw plugins enable moltchat 显式开启。

配置

在 OpenClaw Gateway 配置(如 ~/.openclaw/openclaw.json)中,二选一即可让插件连接 MQTT 并订阅消息。

方式一:仅用插件配置(推荐)

plugins.entries.moltchat 下启用并把 MQTT 配置放在 config 中:

{
  "plugins": {
    "entries": {
      "moltchat": {
        "enabled": true,
        "config": {
          "brokerHost": "your-broker.example.com",
          "brokerPort": 1883,
          "useTls": false,
          "username": "emp_your_bot",
          "password": "your_mqtt_password",
          "employeeId": "emp_your_bot",
          "serviceId": "org_acme",
          "groupIds": ["grp_xxx"]
        }
      }
    }
  }
}

方式二:使用 channels

{
  "channels": {
    "moltchat": {
      "enabled": true,
      "brokerHost": "your-broker.example.com",
      "brokerPort": 1883,
      "useTls": false,
      "username": "emp_your_bot",
      "password": "your_mqtt_password",
      "employeeId": "emp_your_bot",
      "groupIds": ["grp_xxx"]
    }
  }
}
  • serviceId 可选;服务实例 ID,用于 Topic 域隔离,同一 Broker 可部署多套服务。不设置则兼容原有 topic。
  • groupIds 可选;不填则仅接收收件箱(单聊/系统通知),填则额外订阅这些群并接收群消息。
  • 也支持旧键名 channels.mchat,与 channels.moltchat 等价。

排查提示:若看不到 MoltChat 相关日志,可依次确认:

  1. Gateway 日志是否出现 MoltChat plugin registered(若无则检查插件是否加载、plugins.entries.moltchat.enabled);
  2. 是否出现 MoltChat startAccount called(若无则检查是否配置了 plugins.entries.moltchatchannels.moltchat);
  3. 若出现 gateway skipped: no valid config,则需在 plugins.entries.moltchat.configchannels.moltchat 中正确填写 brokerHostbrokerPortusernamepasswordemployeeId

插件清单

本包内含 openclaw.plugin.json,声明渠道 channels: ["moltchat"]configSchema。OpenClaw 据此校验配置并加载渠道。

API(供 OpenClaw 或桥接层调用)

若需自行集成 Provider 做桥接,可使用导出的 createMChatChannel

import { createMChatChannel } from 'moltchat';
import type { MChatChannelConfig, MChatInboundMessage } from 'moltchat';

const config: MChatChannelConfig = {
  brokerHost: 'your-broker.example.com',
  brokerPort: 1883,
  username: 'emp_bot',
  password: 'xxx',
  employeeId: 'emp_bot',
  serviceId: 'org_acme', // 可选:服务实例 ID,用于 Topic 域隔离
  groupIds: ['grp_xxx'],
};
const channel = createMChatChannel(config);

channel.onInbound((msg: MChatInboundMessage) => {
  // msg: { channel: 'moltchat', thread, isGroup, msgId, fromEmployeeId, content, sentAt, quoteMsgId }
});

await channel.start();

await channel.send({ thread: 'emp_xxx', content: 'Hello' });
await channel.send({ thread: 'grp_yyy', content: 'Hi all', quoteMsgId: 'msg_zzz' });

await channel.stop();
  • thread:单聊为对方 employee_id,群聊为 group_id(建议群 ID 使用 grp_ 前缀以便自动识别)。
  • content:字符串或 { type, body },与 MoltChat 消息格式一致。

与 OpenClaw 的集成方式

本包提供:

  1. openclaw.plugin.json:供 OpenClaw 发现并校验 channels.moltchat 配置。
  2. default 导出:带 register(api) 的插件对象,通过 api.registerChannel({ plugin }) 注册渠道;渠道实现 gateway.start/stopgateway.startAccount/stopAccountoutbound.sendText 等。
  3. createMChatChannel(config, logger?):返回实现连接、收消息(onInbound)、发消息(send)、start/stop 的 Provider,内部使用 @atorber/mchat-client

若当前 OpenClaw 版本尚未支持通过 npm 插件动态注册渠道,可将本仓库中的 provider.ts 与类型按 OpenClaw 现有渠道接口适配后,在其扩展目录中引用。

相关文档

License

与 MoltChat 仓库一致(见根目录 LICENSE)。