Skip to content

DotCraft WeCom Channel Adapter

@dotcraft/channel-wecom connects WeCom to DotCraft through the WebSocket external channel protocol. The adapter connects to DotCraft AppServer and starts a local WeCom bot HTTP(S) callback service.

Personal Weixin @dotcraft/channel-weixin and WeCom @dotcraft/channel-wecom are separate channels.

Feature Summary

  • Connects to DotCraft AppServer over WebSocket
  • Starts a WeCom HTTP(S) callback service
  • Supports XML message push APIs and JSON smart bot callback format
  • Supports text, images, speech-to-text, files, attachments, mixed image/text messages, and events
  • Downloads image and mixed image/text message images as temporary local images for multimodal input
  • Isolates conversations by userId + chatId
  • Supports approval inside the WeCom conversation
  • Provides voice and file runtime tools

Prerequisites

RequirementNotes
WeCom botSelf-built app or smart bot with callback URL, Token, and EncodingAESKey
DotCraft AppServerWebSocket mode must be enabled
WeCom channel packageIn releases: resources/modules/channel-wecom; in development: sdk/typescript/packages/channel-wecom
Public callback URLWeCom must reach the adapter callback URL; production deployments should usually expose HTTPS through a reverse proxy

1) Workspace Config (.craft/config.json)

Enable AppServer WebSocket and register the WeCom external channel in .craft/config.json:

json
{
  "AppServer": {
    "Mode": "WebSocket",
    "WebSocket": {
      "Host": "127.0.0.1",
      "Port": 9100,
      "Token": ""
    }
  },
  "ExternalChannels": {
    "wecom": {
      "enabled": true,
      "transport": "websocket"
    }
  }
}

2) Adapter Config (.craft/wecom.json)

Create .craft/wecom.json in the target workspace:

json
{
  "dotcraft": {
    "wsUrl": "ws://127.0.0.1:9100/ws",
    "token": ""
  },
  "wecom": {
    "host": "0.0.0.0",
    "port": 9000,
    "scheme": "http",
    "adminUsers": ["zhangsan"],
    "whitelistedUsers": [],
    "whitelistedChats": [],
    "approvalTimeoutMs": 60000,
    "robots": [
      {
        "path": "/dotcraft",
        "token": "your_token_here",
        "aesKey": "your_43_char_aeskey"
      }
    ]
  }
}

Field reference:

FieldDescriptionDefault
dotcraft.wsUrlDotCraft AppServer WebSocket URLws://127.0.0.1:9100/ws
dotcraft.tokenAppServer WebSocket tokenEmpty
wecom.hostCallback service listen host0.0.0.0
wecom.portCallback service listen port9000
wecom.schemeLocal callback protocol, http or httpshttp
wecom.tls.certPath / keyPathCertificate and private key paths for https modeEmpty
wecom.adminUsersWeCom UserIds with admin permission[]
wecom.whitelistedUsersWeCom UserIds allowed to chat with DotCraft[]
wecom.whitelistedChatsChatIds allowed to chat with DotCraft[]
wecom.approvalTimeoutMsApproval timeout in milliseconds60000
wecom.robotsBot callback credential list[]

Single robot config:

FieldRequiredDescription
pathYesCallback path, such as /dotcraft
tokenYesToken configured in the WeCom console
aesKeyYesEncodingAESKey, usually 43 characters without =

3) WeCom Console Setup

Configure message receiving in the WeCom admin console:

  • URL: http://your-server:9000/dotcraft
  • Token: same as robots[].token in .craft/wecom.json
  • EncodingAESKey: same as robots[].aesKey in .craft/wecom.json

If HTTPS is exposed through Nginx, Caddy, or another reverse proxy, the adapter can still listen on local HTTP.

4) Start

Desktop discovers the packaged wecom-standard external channel and can start it from the channel management UI.

For development:

bash
cd sdk/typescript
npm run build --workspace @dotcraft/channel-wecom
npx dotcraft-channel-wecom --workspace F:\dotcraft

Or from the package directory:

bash
cd sdk/typescript/packages/channel-wecom
npm run build
npm start -- --workspace F:\dotcraft

Usage

  • Files and attachments return diagnostic messages and are not submitted directly to the agent.
  • Conversations are isolated by userId + chatId; channelContext is chat:<ChatId>.
  • /new, /help, Heartbeat, Cron, and common delivery flows are supported.
  • Approval keywords include 同意, 同意全部, 拒绝, yes, yes all, and no.

Runtime Tools

ToolPurposeNotes
WeComSendVoice(filePath)Send voice to the current WeCom chatAMR only; local absolute path; uploads temporary media first
WeComSendFile(filePath)Send a file to the current WeCom chatLocal absolute path; uploads temporary media first

These tools are exposed by the adapter through external channel capabilities. Tool names stay PascalCase.

Cron and Heartbeat

channeltoDelivery targetPrerequisite
"wecom""chat:<ChatId>" or "<ChatId>"WeCom conversationThat ChatId has received a message and the adapter has cached its webhook

It is recommended to create Cron tasks from inside the WeCom conversation so the task automatically binds to the current ChatId. If the target chatId has no cached webhook yet, delivery fails with No WeCom webhook is available for target ....

Apache License 2.0