Chapter 10

Feishu/WeCom/DingTalk Bots

Ch10 Feishu / WeCom / DingTalk Bots

China's top three enterprise chat platforms — Feishu (Lark), WeCom, and DingTalk — all support Webhook-based robots that push messages to group chats. n8n's HTTP Request node connects to all three without any plugin. This chapter covers bot setup for each platform, deep-dives into Feishu's interactive card JSON, implements two-way button interactions, and builds a daily business stats broadcast bot.

Feishu Webhook Bot Setup

In the Feishu group: Settings → Group Bots → Add Bot → Custom Bot → copy the Webhook URL. Use this URL as the HTTP Request target in n8n with method POST and Content-Type: application/json. Three message types are available: plain text (text), rich text (post), and interactive cards (interactive).

Feishu Card Message JSON Deep Dive

Feishu cards use a JSON DSL with three top-level keys: config, header, and elements. Elements are an array of components: div (content with fields), hr (divider), action (buttons), img (image), and note (footer text).

// Feishu interactive card — full example
{
  "msg_type": "interactive",
  "card": {
    "config": { "wide_screen_mode": true },
    "header": {
      "title": { "tag": "plain_text", "content": "Daily Stats Report" },
      "template": "blue"
    },
    "elements": [
      {
        "tag": "div",
        "fields": [
          { "is_short": true, "text": { "tag": "lark_md",
            "content": "**Orders Today**\n{{ $json.orders }}" }},
          { "is_short": true, "text": { "tag": "lark_md",
            "content": "**GMV**\n${{ $json.gmv }}" }}
        ]
      },
      { "tag": "hr" },
      { "tag": "action", "actions": [{
        "tag": "button",
        "text": { "tag": "plain_text", "content": "View Dashboard" },
        "type": "primary",
        "url": "https://dashboard.example.com"
      }]}
    ]
  }
}

Common template color values: blue (info), green (success), yellow (warning), red (alert), grey (neutral). lark_md supports Markdown syntax and is the recommended tag for formatting card content.

Card builder tool: Feishu's open platform provides a visual "Message Card Builder" (card.feishu.cn) for editing and previewing card JSON in real time. Build your card there first, then paste the JSON into n8n.

WeCom Group Bot

WeCom group bot setup: group Settings → Add Robot → copy Webhook URL. POST JSON with msgtype set to text, markdown, image, or news. WeCom's Markdown supports color tags like <font color='warning'>...</font>.

// WeCom Markdown message
{
  "msgtype": "markdown",
  "markdown": {
    "content": "## Alert\n> Server **{{ $json.host }}** CPU usage exceeded 90%\n\nCurrent: <font color='warning'>{{ $json.cpu }}%</font>"
  }
}

Note: group bots are send-only; two-way interaction requires a registered WeCom application.

DingTalk Bot: HMAC Signature Security

DingTalk's "sign" security mode requires adding a timestamp and HMAC-SHA256 signature to each request. In n8n, use a Code node to compute the signature, then reference it in the HTTP Request URL query parameters.

Signing steps:

  1. Get current Unix timestamp in milliseconds: timestamp
  2. Concatenate: timestamp + "\n" + secret
  3. HMAC-SHA256 with secret as key
  4. Base64-encode the result
  5. URL-encode the Base64 string
  6. Append as timestamp and sign query parameters to the Webhook URL

Two-Way Interaction: User Button Clicks Trigger Workflows

Feishu interactive card buttons support two trigger modes:

Webhook bot limitations: Group Webhook bots are push-only. For true bidirectional conversation (users typing in the group to trigger workflows), you need to create a Feishu custom app on the developer platform and subscribe to message events via n8n's Webhook trigger.

Project: Daily Business Stats Broadcast Bot

Goal: every weekday at 9:00 AM, automatically query the day's business data from the database and push a Feishu card to the operations group.

Workflow node chain:

  1. Cron Trigger: 0 9 * * 1-5 (weekdays at 9 AM)
  2. MySQL node (Execute Query): query today's order count, GMV, new users, refund amount
  3. Code node: format numbers (thousands separator, 2 decimal places), compute day-over-day change rate, generate trend emoji (↑ / ↓)
  4. HTTP Request node: POST assembled card JSON to Feishu group Webhook
  5. IF node (error handling): check if response code is 0; if not, push failure alert to ops group

This workflow runs entirely within n8n — no backend code needed. Scheduling, database queries, formatting, and message delivery are all visual node configurations that take effect immediately on the next run.

Rate this chapter
4.5  / 5  (31 ratings)

💬 Comments