npm package: @ferby/moltbot-plugin-dingtalk-wecom
Description: Moltbot plugin for DingTalk (Stream Mode) and WeCom (Webhook)
Latest version: 0.1.3

# Clawdbot DingTalk & WeCom Plugin

This plugin adds support for **DingTalk (钉钉)** and **WeCom (企业微信)** channels to Clawdbot.

## Features

-   **DingTalk**: Uses **Stream Mode** (WebSocket). No public IP or webhook configuration required inside DingTalk.
-   **WeCom**: Uses **Webhook Mode**. Requires a publicly accessible URL (or reverse proxy) to receive messages.

## Installation

1.  Clone the repository.
2.  Install dependencies:

```bash
npm install
```

> **Note**: If you encounter permission errors, try running `sudo chown -R $(whoami) ~/.npm` or use `sudo` (not recommended).

## Configuration

This plugin is configured via your Clawdbot configuration file (e.g., `clawdbot.config.yaml`).

### 1. DingTalk (Stream Mode)

**Prerequisites:**
1.  Go to [DingTalk Open Platform](https://open-dev.dingtalk.com/).
2.  Create an **Internal Enterprise Robot** (应用开发 -> 企业内部开发 -> 机器人).
3.  In the app settings, go to **Rights Management** (权限管理) or **Development Configuration** (开发配置).
4.  Find **Stream Mode** (Stream 模式) and enable it.
5.  Ensure the "Bot Message Callback" topic is subscribed.
6.  Publish the application.
7.  Copy **AppKey** and **AppSecret**.

**Config:**

```yaml
channels:
  dingtalk:
    enabled: true
    appKey: "YOUR_DINGTALK_APP_KEY"
    appSecret: "YOUR_DINGTALK_APP_SECRET"
    # Policies (Optional)
    # dmPolicy: "open" # "open", "pairing", or "allowlist"
    # groupPolicy: "open"
```

### 2. WeCom (Webhook)

**Prerequisites:**
1.  Go to [WeCom Admin Console](https://work.weixin.qq.com/wework_admin/frame).
2.  Create a Self-built Application (应用管理 -> 自建).
3.  Copy **AgentId** and **Secret**.
4.  Copy **CorpId** (My Enterprise -> Enterprise Info).
5.  In the app settings, go to **Receive API** (接收消息).
    *   **URL**: `http://YOUR_SERVER_IP:3001/wecom/webhook`
    *   **Token**: Generate a random string.
    *   **EncodingAESKey**: Generate a random key.
6.  **Important**: Click "Save" in WeCom *after* starting Clawdbot. WeCom validates the URL immediately.

**Config:**

```yaml
channels:
  wecom:
    enabled: true
    corpId: "YOUR_CORP_ID"
    agentId: "YOUR_AGENT_ID"
    secret: "YOUR_WECOM_SECRET"
    token: "YOUR_WECOM_TOKEN" 
    encodingAESKey: "YOUR_WECOM_AES_KEY"
    # Optional
    # webhookPath: "/wecom/webhook" # Default
```

## Running

1.  Start Clawdbot as usual.
2.  **DingTalk**: You should see a log message `dingtalk: stream client connected`.
3.  **WeCom**: Ensure port **3001** is open and accessible from the internet. When you click "Save" in WeCom admin, it will hit this port.

## Usage

-   **DingTalk**: Send a message to the robot in a DM or mention it in a group.
-   **WeCom**: Send a message to the application in WeCom.

## Troubleshooting

-   **DingTalk Disconnects**: Check if AppKey/Secret are correct and if the app is published.
-   **WeCom Url Validation Failed**:
    -   Ensure Clawdbot is running and port 3001 is reachable.
    -   Ensure `token` and `encodingAESKey` in config match WeCom exactly.
    -   Check logs for signature verification errors.