WeCom (Enterprise WeChat) Integration

Table of contents

  1. WeCom (Enterprise WeChat) Integration
    1. Features
    2. Modes
      1. Webhook Mode (Simple, One-Way)
      2. API Mode (Advanced, Bidirectional)
    3. Setup Guide
      1. Webhook Mode
      2. API Mode
    4. Commands
    5. Technical Details
    6. Troubleshooting
      1. Webhook Not Working
      2. API Authentication Errors
    7. Next Steps

WeCom integration with webhook or API mode.

Features

  • Two Modes: Webhook (simple, one-way) or API (bidirectional)
  • Corporate Integration: Full enterprise WeChat support
  • Message Queue: Sequential processing

Modes

Webhook Mode (Simple, One-Way)

Simplest setup, but only supports sending messages to WeCom.

API Mode (Advanced, Bidirectional)

Full bidirectional communication, requires corporate approval.


Setup Guide

Webhook Mode

  1. Add a webhook robot in WeCom group
  2. Copy the webhook key
  3. Configure:
require('chat').setup({
  integrations = {
    wecom = {
      webhook_key = 'YOUR_WEBHOOK_KEY',
    },
  },
})

Webhook mode is the simplest setup but only supports one-way communication.

API Mode

  1. Create an enterprise application
  2. Get CorpID, CorpSecret, and AgentID
  3. Configure:
require('chat').setup({
  integrations = {
    wecom = {
      corp_id = 'YOUR_CORP_ID',
      corp_secret = 'YOUR_CORP_SECRET',
      agent_id = 'YOUR_AGENT_ID',
      user_id = 'YOUR_USER_ID',
    },
  },
})

API mode requires corporate approval and proper application setup.


Commands

Command Description
:Chat bridge wecom Bind current session to WeCom

Technical Details

  • API: WeCom API
  • Authentication: Access Token (auto-refresh)
  • Message Limit: 2,048 characters
  • State Persistence: stdpath('data')/chat-wecom-state.json

Troubleshooting

Webhook Not Working

Symptom: Webhook messages not being sent.

Solution:

  1. Verify webhook key is correct
  2. Check if the webhook robot is enabled
  3. Test with a manual webhook request

API Authentication Errors

Symptom: Cannot authenticate with WeCom API.

Solution:

  1. Verify corp_id and corp_secret are correct
  2. Check if the application is approved
  3. Verify agent_id is correct

Next Steps