凌晨1点33分,我在飞书里问Agent一个问题,2分钟后又去Discord催它。同一个Agent,三头六臂,在飞书、Discord、Telegram、微信上同时在线——这不就是AI版的"分身术"吗?今天手把手教你实现。
一、多渠道架构概述
OpenClaw的消息系统支持同时接入多个渠道,架构如下:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 飞书 │ │ Discord │ │ Telegram │ │ 微信 │
│ (Lark) │ │ │ │ │ │ (WeChat) │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │ │
└────────────────┴────────────────┴────────────────┘
│
┌──────┴──────┐
│ OpenClaw │
│ Gateway │
│ (统一处理) │
└──────┬──────┘
│
┌───────────┼───────────┐
│ │ │
┌────┴────┐ ┌───┴───┐ ┌────┴────┐
│ LLM │ │ Tools │ │ Memory │
│ (大脑) │ │ (手脚)│ │ (记忆) │
└─────────┘ └───────┘ └─────────┘
二、飞书接入
2.1 创建飞书应用
# 步骤:
1. 访问 https://open.feishu.cn/app
2. 创建企业自建应用
3. 获取 App ID 和 App Secret
4. 配置事件订阅(消息接收)
5. 配置权限(消息读写、群组管理)
6. 发布应用
2.2 OpenClaw 飞书配置
# config.yaml
channels:
feishu:
enabled: true
appId: "${FEISHU_APP_ID}"
appSecret: "${FEISHU_APP_SECRET}"
# 权限范围
scopes:
- im:message
- im:message:send_as_bot
- im:chat
- im:resource
# 事件回调
webhook: "https://your-domain.com/webhook/feishu"
# 加密配置
encryptionKey: "${FEISHU_ENCRYPTION_KEY}"
verificationToken: "${FEISHU_VERIFICATION_TOKEN}"
2.3 飞书消息操作
# 发送消息
message({
action: "send",
channel: "feishu",
target: "oc_c942dfd09730eb94bf838c6519c115e9",
message: "今日AI新闻日报已生成!"
})
# 发送富文本消息
message({
action: "send",
channel: "feishu",
target: "oc_c942dfd09730eb94bf838c6519c115e9",
message: "🔥 AI热点速报",
filePath: "/var/www/miaoquai/news/daily-report.html"
})
三、Discord 接入
3.1 创建 Discord Bot
# 步骤:
1. 访问 https://discord.com/developers/applications
2. 创建 New Application
3. 创建 Bot 并获取 Token
4. 配置 Bot 权限(Send Messages、Embed Links等)
5. 使用 OAuth2 URL 邀请 Bot 到服务器
6. 开启 Message Content Intent 和 Server Members Intent
3.2 OpenClaw Discord 配置
# config.yaml
channels:
discord:
enabled: true
token: "${DISCORD_BOT_TOKEN}"
# 服务器配置
guilds:
- id: "your-guild-id"
# 允许Bot响应的频道
allowedChannels:
- "general"
- "ai-tools"
- "news"
# 管理员频道(Bot优先响应)
adminChannel: "bot-commands"
# 命令前缀
prefix: "!"
# 活动状态
activity:
name: "帮你找AI工具 | miaoquai.com"
type: "playing"
3.3 Discord 消息发送
# 发送到指定频道
message({
action: "send",
channel: "discord",
target: "1483699648890802201",
message: "🌅 早安AI!今日热点新闻..."
})
# 发送带嵌入的消息
message({
action: "send",
channel: "discord",
target: "1483699648890802201",
card: {
title: "AI新闻日报",
description: "今日AI领域5大热点",
color: 0xFF6B35,
url: "https://miaoquai.com/news/2026-04-18.html"
}
})
四、Telegram 接入
4.1 创建 Telegram Bot
# 步骤:
1. 在 Telegram 中搜索 @BotFather
2. 发送 /newbot 创建新机器人
3. 设置名称和用户名
4. 获取 Bot Token
5. (可选)设置 Webhook 接收消息
4.2 OpenClaw Telegram 配置
# config.yaml
channels:
telegram:
enabled: true
token: "${TELEGRAM_BOT_TOKEN}"
# 允许的用户/群组(白名单)
allowedChats:
- type: "private"
id: "your-telegram-user-id"
- type: "group"
id: "-1001234567890"
# 命令处理
commands:
- command: "news"
description: "获取最新AI新闻"
- command: "tools"
description: "搜索AI工具"
- command: "help"
description: "帮助信息"
五、微信/QQ 接入
5.1 QQ 机器人接入
# OpenClaw 通过插件支持QQ机器人
channels:
qqbot:
enabled: true
appId: "${QQBOT_APP_ID}"
token: "${QQBOT_TOKEN}"
# 群聊配置
groups:
- id: "group-open-id"
name: "AI工具交流群"
# 私聊配置
allowPrivate: true
六、跨渠道消息管理
6.1 统一消息格式
OpenClaw 会自动将不同渠道的消息转换为统一格式:
| 功能 | 飞书 | Discord | Telegram |
|---|---|---|---|
| 文本消息 | ✅ | ✅ | ✅ |
| 图片发送 | ✅ | ✅ | ✅ |
| 文件附件 | ✅ | ✅ | ✅ |
| 富文本/嵌入 | ✅ Card | ✅ Embed | ✅ Markdown |
| 语音消息 | ✅ | ✅ | ✅ |
| 群管理 | ✅ | ✅ | ✅ |
6.2 定时跨渠道推送
# 同时推送到多个渠道的定时任务
cron({
job: {
name: "每日新闻多渠道推送",
schedule: { kind: "cron", expr: "0 8 * * *", tz: "Asia/Shanghai" },
payload: {
kind: "agentTurn",
message: "生成今日AI新闻日报,同时推送到飞书群和Discord频