Integrations

WeCom Integration

Connect a WeCom smart-bot to Mopheus. Chat with agents directly in WeCom, receive ticket updates back in WeCom chats.

The WeCom integration connects a WeCom smart-bot (aibot) to Mopheus via a WebSocket long-connection. Once configured, agents respond to WeCom messages in real time, and ticket status changes and comments are pushed back to the originating WeCom chat.

Connection Method Comparison

ComparisonGroup BotSelf-built AppSmart Bot (URL Callback)Smart Bot (WebSocket Long Connection)
Direct messagesNot supportedSupportedSupportedSupported
Group chatsReceives messages in groups the group bot has joinedCan create group chats and send messages to groups created by the appSupports @-mention interaction in groupsSupports @-mention interaction in groups
Multiple groupsAfter the same bot joins multiple groups, it can send messages to those groupsThe group must be created by the appCan join groups for interactionCan join groups for interaction
Public endpointNo public callback URL is needed to receive group messagesA publicly reachable callback URL is required to receive messages; API calls also require a trusted IPRequires a publicly reachable callback URLNo public callback URL is required; the deployment must be able to connect to WeCom's WebSocket service
Reply windowSuitable for group message delivery; does not provide direct-message interactionFollows the app messaging API rulesresponse_url is valid for one hour and can be used onceNot subject to the one-hour URL callback response_url limit
Mopheus supportGroup bot configuration and multi-group broadcast are not supportedBinding is supported; currently direct messages onlyNot supportedQR-code or manual binding is supported

The group-bot, multi-group, and smart-bot capabilities above describe WeCom. Mopheus support is listed in the final row. The one-hour URL callback limit is the validity period of response_url; it does not mean the bot must keep replying for one hour.

Setup

1. Smart Bot Setup

  1. In Mopheus, open an agent or team detail page → Integrations → Connect WeCom Bot.
  2. Select Connect by QR Code, scan the displayed QR code in WeCom, then finish creation and authorization in WeCom.
  3. Once the scan succeeds, Mopheus receives the Bot ID and Secret server-side and stores them encrypted for the selected agent or team. Credentials are never returned to the browser.

The installation entry requires the current member to have the channel:bind permission. Installing a bot for another agent or a team also follows the workspace ownership rule.

Enter Credentials Manually

  1. Go to the WeCom Admin Console → Application Management → Smart Bot.
  2. Create a new smart bot. Note the Bot ID and Secret shown once at creation.
  3. In Mopheus, open an agent or team detail page → Integrations → Connect WeCom Bot, then select Enter Credentials Manually.
  4. Fill in the Bot ID and Secret. Optionally set a custom WebSocket URL (defaults to wss://openws.work.weixin.qq.com).

2. Self-built App (Callback Mode)

  1. In the WeCom Admin Console, open Application Management and create an app. Open its details and note the AgentId and Secret.
  2. In Mopheus, open an agent or team detail page → Integrations → Connect WeCom Bot, then select Self-built App. Find the Corp ID at the bottom of My Enterprise in the WeCom Admin Console, then enter the Corp ID, Agent ID, and app Secret. Mopheus securely generates the callback Token and EncodingAESKey and stores them encrypted.
  3. After creating the integration, copy the displayed callback URL, Token, and EncodingAESKey. Return to the app details in WeCom, open Receive Messages, select Set API Receive, enter the copied values, and save. The callback URL is generated from the deployment's APP_URL and the fixed path /wecom/callback/{installationId}; Next.js forwards requests to the Go API, so the public Web domain must be reachable and NEXT_PUBLIC_API_URL must point to the backend.
  4. WeCom API Base URL defaults to https://qyapi.weixin.qq.com. Set the API base URL for a private deployment when needed. Mopheus obtains an access token with GET /cgi-bin/gettoken?corpid=<CorpID>&corpsecret=<Secret>, then sends messages with POST /cgi-bin/message/send?access_token=<access_token>.

Self-built app outbound messages use WeCom's Markdown message type. Content retains the existing 20 KB overall channel limit; within that limit, content over 2048 bytes is split into multiple messages at UTF-8-safe boundaries, preferring line breaks. WeCom renders only a subset of Markdown syntax.

Inbound image, file, and video callbacks download their MediaId through the configured API base URL and attach the stored file to the channel message. Outbound sends to the same member are paced at least four seconds apart (900/hour maximum); WeCom 45009 rate-limit responses are retried by the outbound queue. The account-wide daily allowance depends on the enterprise's member-cap tier (cap × 200) and is not currently known to Mopheus, so configure the app's allowed send scope conservatively in WeCom.

This mode reads the member UserID from callback XML FromUserName and reuses Mopheus's existing WeCom identity binding and channel engine. The app Secret, callback Token, and EncodingAESKey are encrypted at rest.

3. Configure Mopheus

In Admin → System Config, set:

SettingValue
Enable WeCom (wecom_enabled)true
WeCom Secret Key (wecom_secret_key)A base64-encoded 32-byte AES key for encrypting stored bot secrets — generate via the Generate button in System Config

After bot credentials are configured, do not edit the WeCom secret key through the generic config editor. Generate in System Config rotates the key and re-encrypts every existing WeCom binding in one transaction.

Before verifying the integration, configure the bot's visibility or available members and departments in the WeCom Admin Console. Connecting the bot does not automatically authorize every WeCom user. A sender outside the bot's available range may be rejected by WeCom before Mopheus receives the message.

4. Verify

Send any message to the bot in WeCom. On the first message, each WeCom sender receives a one-time Mopheus account binding link. Sign in and confirm the binding, then send the message again. The message is routed to the assigned agent, and the agent's reply is pushed back to the WeCom chat automatically.

The binding is per WeCom sender and per bot installation. The person who connected the bot must also complete this step when they first use the bot; WeCom does not provide Mopheus with the installer's WeCom user identity during installation.

WeCom bot availability and Mopheus account binding are separate requirements: each sender must be within the bot's available range and must complete the one-time Mopheus binding flow.

The integration section identifies the Mopheus workspace member who installed each bot binding.


How It Works

Inbound: WeCom → Mopheus

WeCom user sends message to smart-bot
        │
        ▼
aibot_msg_callback over WebSocket
        │
        ▼
Mopheus channel engine receives and routes message
        │
        ▼
Session created → agent task enqueued
        │
        ▼
Agent runs, produces reply
        │
        ▼
Patcher sends reply back to WeCom chat via aibot_send_msg

Outbound: Mopheus → WeCom

The Patcher component handles all outbound traffic via the shared WebSocket connection.

EventWeCom message sent
Agent reply readyMarkdown reply with agent name header
Agent task failedError card with failure detail
Ticket status changedStatus update with ticket reference
Comment added to ticketMarkdown preview with ticket reference and truncated body
Inbox notificationMarkdown card sent to the user's 1:1 DM with the bot

All outbound messages are sent as msgtype: markdown. Plain text renders correctly through the markdown path. Messages are rune-safe truncated to 4000 bytes.


Multi-Replica Constraint

The WeCom bot allows a single live WebSocket subscriber per bot. Mopheus enforces single-replica via the channel supervisor lease. If you scale Mopheus horizontally, set up Redis Streams relay (separate feature) before enabling the WeCom integration.

Message History

The smart-bot long connection receives only real-time events delivered to the bot. This integration does not pull ordinary group-chat history. WeCom conversation-content archiving is a separate compliance capability and is not part of smart-bot connection setup.


Troubleshooting

SymptomCheck
Bot does not respondVerify Enable WeCom (wecom_enabled) is true and the assigned agent is bound to an enabled, online runtime. A configured fallback runtime can also resume queued work.
"invalid bot_id or secret" in logsThe Bot ID or Secret entered during installation is incorrect — reconnect with correct credentials
No outbound notificationsConfirm the bot's WebSocket connection is active (check server logs for "wecom: subscribe ok")
No agent replyConfirm the assigned agent is bound to an enabled, online runtime. A configured fallback runtime can also resume queued work.