Connect AI Agent to Enterprise IM: 4 Steps for Feishu, DingTalk & WeCom
No firewall changes, no public server needed — get AI Agent into WeChat Work / Feishu / DingTalk in 30 minutes with Stream-mode real-time push
2026-08-24 · Leo · Tutorial · 8 min read
TL;DR — Integrating AI Agent with enterprise IM (Feishu / DingTalk / WeCom) takes just 4 steps: ① Choose Webhook callback mode (no public IP needed) → ② Configure the IM platform's Outgoing webhook URL → ③ Write a Flask receiver (10-line Python) → ④ Connect to Mule Agent's IM channel. Stream mode delivers typing-effect real-time push — 10x better UX than polling.
1. Understand the Two Integration Patterns First
There are two ways to connect AI Agent to enterprise IM — picking the wrong one adds hours of work:
| Pattern | How it works | Needs public IP? | Best for |
| Persistent connection (Agent → IM) | AI Agent pushes messages to IM proactively | ✅ Yes | Companies with a fixed outbound server |
| Webhook callback (IM → Agent) | IM POSTs user messages to your service | ❌ No | Intranet / no server /不想暴露端口 |
| Hybrid | Webhook receives + Agent pushes back | ✅ Agent side only | Bidirectional real-time conversation |
For most teams, Webhook callback is the best starting point: no firewall changes, no cloud server needed. Mule Agent provides a stable callback receiver — users message the IM, the IM forwards to Agent, Agent processes and replies back.
2. Step 1: Configure IM Channel in Mule Agent (~5 min)
Step 1: Open Mule Agent Admin Dashboard
Go to
Channel Management →
Add Channel, select your target platform:
- Feishu: Use a Feishu self-built app, fill in App ID + App Secret
- DingTalk: Internal enterprise app, fill in Corp ID + App Key + App Secret
- WeCom (企业微信): Self-built enterprise app, fill in Corp ID + Agent ID + App Secret
After setup, Mule Agent generates a webhook callback URL like:
https://your-agent-domain.com/webhook/feishu
This URL is what you paste into the IM platform's Outgoing webhook config.
3. Step 2: Configure Outgoing Webhook on Each IM Platform (~10 min)
Feishu Configuration
Step 2a: Feishu Enterprise Self-Built App
- Go to Feishu Open Platform → find your self-built app
- Add App Capabilities → Bot, enable bot capability
- Event Subscriptions → check
im.message.receive_v1
- Request URL → paste the Mule Agent callback URL (HTTPS required)
- Publish the app version, wait for enterprise admin approval
⚠️ Feishu requires HTTPS callback URLs with a fully verified domain. If you don't have HTTPS yet, use Let's Encrypt (see Pitfall 1 below).
DingTalk Configuration
Step 2b: DingTalk Internal Enterprise App
- Go to DingTalk Open Platform → Internal Development → find your app
- Message Push → Bot → Enable custom bot
- Message Receive → configure callback URL (Token + EncodingAESKey auto-generated by Mule Agent)
- Subscribe to event:
im.message.receive
- Save — DingTalk will send a test message to verify connectivity
WeCom Configuration
Step 2c: WeCom Self-Built App
- WeCom Admin Console → Apps → find your self-built app
- Trusted IPs → add Mule Agent server IP (can skip if Agent is on intranet)
- Receive Messages → configure callback URL (HTTPS required)
- Enable App Messaging permission, save
4. Step 3: Write the Message Receiver Service (~10 min)
Step 3: Flask Receiver + Forward to Mule Agent (working code)
Minimal Flask service that receives IM callbacks and forwards to Mule Agent:
import os
from flask import Flask, request, jsonify
import requests
app = Flask(__name__)
MULE_AGENT_TOKEN = os.environ.get("MULE_AGENT_TOKEN", "your-agent-token")
MULE_AGENT_API = "https://your-agent-domain.com/api/chat"
@app.route("/webhook/feishu", methods=["POST"])
def feishu_webhook():
body = request.json
user_msg = body.get("text", {}).get("content", "")
resp = requests.post(
MULE_AGENT_API,
headers={"Authorization": f"Bearer {MULE_AGENT_TOKEN}"},
json={"message": user_msg},
timeout=30
)
agent_reply = resp.json().get("reply", "")
return jsonify({"msg_type": "text", "content": {"text": agent_reply}})
@app.route("/webhook/dingtalk", methods=["POST"])
def dingtalk_webhook():
body = request.json
user_msg = body.get("text", {}).get("content", "")
resp = requests.post(
MULE_AGENT_API,
headers={"Authorization": f"Bearer {MULE_AGENT_TOKEN}"},
json={"message": user_msg},
timeout=30
)
agent_reply = resp.json().get("reply", "")
return jsonify({"msgtype": "text", "text": {"content": agent_reply}})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=False)
Deploy this on a server with public access (or use cloud functions / containers). For production: add signature verification, timeout handling, and logging.
5. Step 4: Enable Stream Mode for Real-Time Typing Effect (~5 min)
Step 4: Stream Mode — AI replies appear character by character
Traditional mode waits for the full response before sending — users wait 5-30 seconds. Stream mode pushes chunks as they're generated, so users see "typing" feedback:
import os, json
from flask import stream_with_context, Response
import requests
MULE_AGENT_API = "https://your-agent-domain.com/api/chat/stream"
MULE_AGENT_TOKEN = os.environ.get("MULE_AGENT_TOKEN", "your-agent-token")
@app.route("/webhook/feishu/stream", methods=["POST"])
def feishu_stream():
body = request.json
user_msg = body.get("text", {}).get("content", "")
def generate():
resp = requests.post(
MULE_AGENT_API,
headers={
"Authorization": f"Bearer {MULE_AGENT_TOKEN}",
"Accept": "text/event-stream"
},
json={"message": user_msg},
stream=True, timeout=60
)
for line in resp.iter_lines():
if line:
yield f"data: {json.dumps({'msg_type':'text','content':line.decode()})}\n\n"
return Response(
stream_with_context(generate()),
mimetype="text/event-stream"
)
Stream mode shines for long-form generation (reports, code, document summaries) — users get instant feedback instead of staring at a blank screen.
6. Troubleshooting: 4 Common Pitfalls
Pitfall 1: HTTPS Certificate Issues
Symptom
Feishu/WeCom reports "signature verification failed" or "connection timeout" — but the service is clearly online.
Root cause
Self-signed cert, or incomplete Let's Encrypt chain. Feishu validates the full certificate chain.
Fix: Use full Let's Encrypt chain (include fullchain.pem, not just cert.pem); set up certbot auto-renew (certs expire every 90 days); or use a cloud load balancer that handles certs automatically.
Pitfall 2: Feishu Signature Verification Blocking Requests
Symptom
curl from local machine works fine, but Feishu messages get no response.
Root cause
Feishu sends a signature header (
X-Lark-Signature) with every request. Without signature verification, Feishu stops retrying (it gradually degrades delivery for non-responsive endpoints).
Fix: Add signature verification in production (Feishu has official examples); for testing, you can temporarily disable signature verification in the Feishu app settings (test environments only).
Pitfall 3: Message Body Field Name Mismatch Across Platforms
Symptom
Works perfectly for Feishu, but DingTalk gets no messages — same code.
Root cause
Three platforms, three different message body structures. Feishu uses
{"text": {"content": "..."}}, DingTalk uses a slightly different parent key, WeCom yet another format.
Fix: Write a separate route for each platform, don't share code. Use each platform's built-in "send test message" feature to confirm the actual payload structure. Log request.json for debugging.
Pitfall 4: Stream Mode Timeout Triggers IM "Service Unavailable"
Symptom
Long AI response causes WeCom/Feishu to show "service temporarily unavailable."
Root cause
IM platforms enforce a per-request timeout (typically 30-60s). Long generation exceeds this limit.
Fix: Push in chunks (every ~200 chars) instead of waiting for full generation; for responses that exceed the limit, truncate and append "Full content at: [link]".
7. SOP: 30 Minutes from Zero to IM Integration
- Step 1 (5 min): In Mule Agent admin → Channel Management, add your target IM platform and get the webhook callback URL.
- Step 2 (10 min): In the IM platform's developer console, configure Outgoing callback URL, enable bot capability, subscribe to message receive events.
- Step 3 (10 min): Deploy Flask receiver (use the code above), verify callback URL is reachable (test with curl locally + IM platform test message).
- Step 4 (5 min): Enable Stream mode for real-time typing effect; optionally configure a daily scheduled task to push morning reports to group chats at 9 AM.
🤝 Want to connect AI Agent to your Feishu, DingTalk, or WeCom? Mule Agent supports all three platforms. Email
278946228@qq.com for an integration plan.
Running these problems at work?
One console for Feishu / WeCom / DingTalk / Weixin / QQ — policies on demand, no more chasing colleagues
Free consultation →