SuperAPI AI Directory

wecom-bot

General & other

View repository

Updated 10-15 16:46

About this skill

WeCom Group Robot

Push messages to WeCom groups via Webhook, supporting text, Markdown, images, news, files, template cards, and other message types.

Documentation Source:https://developer.work.weixin.qq.com/document/path/99398

⚠️ Important Notice

Prerequisites

  1. You need to first add a group robot in the WeCom group to get the Webhook URL
  2. Webhook URL format:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY
  3. Each robot's key is unique, please keep it safe

Message Limits

  • Each robot cannot send more than 20 messages per minute
  • Text messages max 2048 bytes
  • Image size cannot exceed 2MB
  • Markdown does not support @mentioning users

Setup Configuration

1. Create a Group Robot

  1. On WeCom PC or mobile, enter the target group chat
  2. Click Group Settings → Group Robot → Add Robot
  3. Set the robot name and avatar
  4. Copy the generated Webhook URL

2. Store Credentials

Credential configuration supports the following methods (sorted by priority):

Method 1: Environment Variables (highest priority)

export WECOM_BOT_WEBHOOK="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY"

Method 2: clawdbot Configuration File (recommended)

In ~/.clawdbot/clawdbot.json configure:

{
  "skills": {
    "entries": {
      "wecom-bot": {
        "env": {
          "WECOM_BOT_WEBHOOK": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY"
        }
      }
    }
  }
}

Method 3: Multi-Robot Configuration

If you need to send messages to multiple groups, you can configure multiple Webhooks:

{
  "skills": {
    "entries": {
      "wecom-bot": {
        "env": {
          "WECOM_BOT_WEBHOOK": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=DEFAULT_KEY",
          "WECOM_BOT_WEBHOOK_ALERT": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ALERT_KEY",
          "WECOM_BOT_WEBHOOK_DAILY": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=DAILY_KEY"
        }
      }
    }
  }
}

Security Notice: The Webhook URL contains a key; if leaked, it can be maliciously called by others, please keep it safe


Message Types

1. Text Message

The most basic message type, supports @mentioning group members.

Request Example:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "text",
    "text": {
      "content": "Hello, 这是一条测试消息"
    }
  }'

@Mention Users:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "text",
    "text": {
      "content": "请查看今日报告",
      "mentioned_list": ["userid1", "userid2", "@all"],
      "mentioned_mobile_list": ["13800138000"]
    }
  }'

Parameter Description:

Parameter Required Description
content Yes Text content, max 2048 bytes
mentioned_list No userid list,@all means notify everyone
mentioned_mobile_list No Mobile number list, notify specified members in the group

2. Markdown Message

Supports rich text messages in Markdown format.

Request Example:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "markdown",
    "markdown": {
      "content": "# 今日 AI 论文速递\n\n**新增论文**:<font color=\"info\">12 篇</font>\n\n> 重点关注:GPT-5 架构分析\n\n[点击查看详情](https://example.com)"
    }
  }'

Supported Markdown Syntax:

  • Heading:# 一级标题 ## 二级标题 ... ###### 六级标题
  • Bold:**粗体**
  • Link:[链接文字](URL)
  • Quote:> 引用内容
  • Font color:
    • <font color="info">绿色</font>
    • <font color="comment">灰色</font>
    • <font color="warning">橙红色</font>

⚠️ Note: Markdown messages do not support @mentioning users


3. Image Message

Send an image (base64 encoding required).

Request Example:

# 先将图片转为 base64
IMAGE_BASE64=$(base64 -i image.png)
IMAGE_MD5=$(md5 -q image.png)  # macOS
# IMAGE_MD5=$(md5sum image.png | cut -d ' ' -f1)  # Linux

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d "{
    \"msgtype\": \"image\",
    \"image\": {
      \"base64\": \"$IMAGE_BASE64\",
      \"md5\": \"$IMAGE_MD5\"
    }
  }"

Parameter Description:

Parameter Required Description
base64 Yes Base64 encoding of the image content
md5 Yes MD5 value of the image content

Limit: Image size cannot exceed 2MB, supports JPG and PNG formats


4. News Message

Similar to official account news links, supports click-to-jump.

Request Example:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "news",
    "news": {
      "articles": [
        {
          "title": "今日 AI 论文精选",
          "description": "GPT-5 架构深度解析,附完整技术分析",
          "url": "https://example.com/article/1",
          "picurl": "https://example.com/images/cover.png"
        }
      ]
    }
  }'

Multiple News Items:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "news",
    "news": {
      "articles": [
        {
          "title": "论文一:Scaling Law 新发现",
          "description": "MIT 最新研究揭示大模型训练规律",
          "url": "https://example.com/1",
          "picurl": "https://example.com/1.png"
        },
        {
          "title": "论文二:多模态融合新方法",
          "description": "Google DeepMind 发布新架构",
          "url": "https://example.com/2",
          "picurl": "https://example.com/2.png"
        }
      ]
    }
  }'

Parameter Description:

Parameter Required Description
title Yes Title, no more than 128 bytes
description No Description, no more than 512 bytes
url Yes Link to jump to after clicking
picurl No Image link for the news message, supports JPG and PNG

Limit: supports 1-8 news items


5. File Message

Send a file (media_id must be obtained by uploading first).

Step 1: Upload File

curl -X POST "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=YOUR_KEY&type=file" \
  -F "media=@report.pdf"

Example response:

{
  "errcode": 0,
  "errmsg": "ok",
  "type": "file",
  "media_id": "3a8asd892asd8asd",
  "created_at": "1380000000"
}

Step 2: Send File

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "file",
    "file": {
      "media_id": "3a8asd892asd8asd"
    }
  }'

Limit: file size no more than 20MB


6. Template Card Message

A richer interactive card that supports multiple layouts.

Text Notification Card:

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "template_card",
    "template_card": {
      "card_type": "text_notice",
      "source": {
        "desc": "AI 论文助手",
        "desc_color": 0
      },
      "main_title": {
        "title": "今日论文速递",
        "desc": "2025年1月31日"
      },
      "emphasis_content": {
        "title": "12",
        "desc": "篇新论文"
      },
      "sub_title_text": "涵盖 NLP、CV、多模态等领域",
      "horizontal_content_list": [
        {"keyname": "重点领域", "value": "大语言模型"},
        {"keyname": "来源", "value": "arXiv"}
      ],
      "jump_list": [
        {
          "type": 1,
          "url": "https://example.com/papers",
          "title": "查看详情"
        }
      ],
      "card_action": {
        "type": 1,
        "url": "https://example.com/papers"
      }
    }
  }'

Card Type:

card_type Description
text_notice Text Notification
news_notice News Display
button_interaction Button Interaction
vote_interaction Voting Selection

Return Result

Success:

{
  "errcode": 0,
  "errmsg": "ok"
}

Common Error Codes:

errcode Description Solution
0 Success -
93000 Incorrect Webhook key Check the key in the Webhook URL
93004 The bot has been removed from the group Re-add the bot to the group
93008 Invalid message type Check the msgtype parameter
93017 Parameter error Check the request body format
45033 Message sending rate limit exceeded Reduce the sending rate (upper limit 20 messages/minute)

Common Scenario Examples

Scenario 1: Scheduled Daily Report Sending

# 每天早上 9 点发送 AI 论文日报
curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "markdown",
    "markdown": {
      "content": "# 📚 AI 论文日报\n\n**日期**:2025-01-31\n\n## 今日精选\n\n1. **GPT-5 架构分析** - OpenAI\n   > 揭示下一代大模型的技术路线\n\n2. **多模态推理新范式** - Google\n   > 图文联合推理效果提升 30%\n\n[点击查看完整报告](https://example.com)"
    }
  }'

Scenario 2: Monitoring Alerts

# 服务异常时发送告警
curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "text",
    "text": {
      "content": "⚠️ 服务告警\n\n服务名:API Gateway\n状态:响应超时\n时间:2025-01-31 14:30:00\n\n请相关同事尽快处理!",
      "mentioned_list": ["@all"]
    }
  }'

Scenario 3: Competitor Updates Push

curl -X POST "$WECOM_BOT_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{
    "msgtype": "news",
    "news": {
      "articles": [
        {
          "title": "🔍 竞品动态:XX 产品发布新版本",
          "description": "新增 AI 助手功能,支持智能问答和自动摘要",
          "url": "https://example.com/competitor-update",
          "picurl": "https://example.com/competitor.png"
        }
      ]
    }
  }'

One-Click Send Script

Create a convenient script to send messages quickly:

cat > ~/.config/wecom-bot/send.sh << 'EOF'
#!/bin/bash
# 企业微信群机器人消息发送脚本
# 用法: send.sh "消息内容" [markdown|text]

WEBHOOK="${WECOM_BOT_WEBHOOK}"
CONTENT="$1"
TYPE="${2:-text}"

if [ -z "$WEBHOOK" ]; then
  echo "错误: 未配置 WECOM_BOT_WEBHOOK 环境变量"
  exit 1
fi

if [ -z "$CONTENT" ]; then
  echo "用法: $0 \"消息内容\" [markdown|text]"
  exit 1
fi

if [ "$TYPE" = "markdown" ]; then
  curl -s -X POST "$WEBHOOK" \
    -H "Content-Type: application/json" \
    -d "{\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"$CONTENT\"}}"
else
  curl -s -X POST "$WEBHOOK" \
    -H "Content-Type: application/json" \
    -d "{\"msgtype\":\"text\",\"text\":{\"content\":\"$CONTENT\"}}"
fi
EOF

chmod +x ~/.config/wecom-bot/send.sh

How to Use:

# 发送文本
~/.config/wecom-bot/send.sh "Hello, 这是一条测试消息"

# 发送 Markdown
~/.config/wecom-bot/send.sh "# 标题\n内容" markdown

Integration with Other Tools

Working with Clawdbot Scheduled Tasks

# 每天早上 9 点推送 AI 日报到企微群
name: ai-daily-report
schedule: "0 9 * * *"
tasks:
  - name: 抓取论文
    action: fetch_arxiv
  - name: AI 总结
    action: summarize
  - name: 推送企微
    action: wecom_notify
    webhook: $WECOM_BOT_WEBHOOK

Working with Lexiang Knowledge Base

Scrape information → store it in Lexiang → push a summary to the WeCom group, forming a complete closed loop of information flow.