# WeCom (Enterprise WeChat)

This guide covers setting up Qwen Code with a WeCom intelligent robot (企业微信智能机器人).

## Prerequisites

- A WeCom organization account
- A WeCom intelligent robot created in API mode
- The robot's Bot ID and Secret

## Creating the Robot

1. Open the WeCom admin console and create an intelligent robot.

![](https://gw.alicdn.com/imgextra/i2/O1CN017w1jWj1TTvNBcfya8_!!6000000002384-2-tps-2212-887.png)

2. Choose API mode.

![](https://gw.alicdn.com/imgextra/i3/O1CN01buuik0207paQUuLQW_!!6000000006803-1-tps-1276-720.gif)

3. Copy the Bot ID and Secret.
4. Add the robot to the direct chats or groups where it should be available.

The intelligent robot uses a WebSocket connection from Qwen Code to WeCom. You do not need a public callback URL, Token, EncodingAESKey, Corp ID, or Agent ID.

## Configuration

Add the channel to `~/.qwen/settings.json`:

```json
{
  "channels": {
    "my-wecom": {
      "type": "wecom",
      "botId": "$WECOM_BOT_ID",
      "secret": "$WECOM_SECRET",
      "senderPolicy": "allowlist",
      "allowedUsers": ["zhangsan"],
      "sessionScope": "user",
      "cwd": "/path/to/your/project",
      "instructions": "You are a concise coding assistant responding via WeCom.",
      "groupPolicy": "open",
      "groups": {
        "*": { "requireMention": true }
      }
    }
  }
}
```

Set the credentials as environment variables:

```bash
export WECOM_BOT_ID=<your-bot-id>
export WECOM_SECRET=<your-secret>
```

Or define them in the `env` section of `settings.json`:

```json
{
  "env": {
    "WECOM_BOT_ID": "your-bot-id",
    "WECOM_SECRET": "your-secret"
  }
}
```

## Running

```bash
qwen channel start my-wecom
```

Open WeCom and send a message to the intelligent robot.

## Access Control

`senderPolicy` works the same way as other IM channels:

- `allowlist`: only users in `allowedUsers` can use the bot. This is the recommended enterprise default.
- `pairing`: users must pair before using the bot.
- `open`: anyone who can message the robot can use it.

For groups, set `groupPolicy` to `"allowlist"` or `"open"`. By default, group messages require a mention through `"requireMention": true`.

When the WeCom SDK includes explicit mention metadata, Qwen Code uses it for this gate. If no mention metadata is present, the channel treats delivered group messages as unmentioned. Set `"requireMention": false` only if you want to rely on WeCom-side delivery scoping instead.

## Images and Files

Users can send text, voice messages with transcription, images, mixed text plus images, files, and videos. Images are passed to the agent as image attachments. Files and videos are downloaded to temporary local paths so the agent can read them with file tools.

Assistant responses are sent as WeCom markdown. To send a local image generated by the agent, include one marker outside code blocks:

```text
[IMAGE: /absolute/path/to/image.png]
```

For safety, local image paths must be inside the channel file directory under the system temporary directory, such as `/tmp/channel-files/...` on Linux. Generic file, video, and voice upload markers are ignored because model-produced file paths could otherwise upload arbitrary workspace files.

## Troubleshooting

### Bot does not connect

- Verify the Bot ID and Secret.
- Make sure the robot is created in API mode.
- Check that the environment variables are available in the shell running `qwen channel start`.

### Bot does not respond in groups

- Check `groupPolicy`.
- Mention the bot unless the group config sets `"requireMention": false`.
- Confirm the robot has been added to the group.

### Self-built application credentials do not work

This channel is for WeCom intelligent robots. Self-built application callback credentials such as Corp ID, Agent ID, Token, and EncodingAESKey are not used by this channel.
