导读:配置好消息渠道后,你的OpenClaw AI就能在Discord、Telegram、Slack等平台与用户对话。本教程涵盖主流平台的详细配置步骤。
📋 功能介绍
OpenClaw支持多种消息渠道,统一的消息接口:
- Discord - 游戏/开发者社区首选
- Telegram - 全球化,速度快
- Slack - 企业团队协作
- 微信 - 国内用户覆盖
- 飞书 - 字节跳动生态
- 钉钉 - 阿里生态
🎮 Discord配置
步骤1:创建Discord Bot
- 访问 Discord开发者门户
- 点击"New Application",输入应用名称
- 左侧菜单选择"Bot",点击"Add Bot"
- 在Bot页面找到Token,点击"Copy"
步骤2:获取频道ID
# 在Discord中开启开发者模式
设置 → 高级 → 开发者模式(开启)
# 右键点击频道 → 复制频道ID
# 格式如:1234567890123456789
步骤3:OpenClaw配置
# 编辑配置文件
nano ~/.openclaw/config.yaml
channels:
discord:
enabled: true
bot_token: "YOUR_BOT_TOKEN_HERE"
default_channel: "1234567890123456789"
intents:
- guild_messages
- direct_messages
- message_content
步骤4:邀请Bot加入服务器
# 在Discord开发者门户
# OAuth2 → URL Generator
# 勾选 bot + 所需权限
# 复制生成的URL,在浏览器中打开
# 选择要加入的服务器
使用示例
# 通过Discord发送消息
openclaw message send \
--channel discord \
--to "1234567890123456789" \
--text "Hello from OpenClaw!"
# JavaScript API
const { message } = require('openclaw');
await message.send({
channel: 'discord',
target: '1234567890123456789',
content: '自动化消息发送测试'
});
📱 Telegram配置
步骤1:创建Telegram Bot
- 在Telegram中搜索 @BotFather
- 发送
/newbot - 按提示输入Bot名称和用户名(必须以bot结尾)
- 保存返回的API Token
步骤2:获取Chat ID
# 方法1:访问
https://api.telegram.org/bot/getUpdates
# 在返回的JSON中找到 chat.id
# 格式如:123456789
# 方法2:发送消息给Bot,然后查看
步骤3:OpenClaw配置
channels:
telegram:
enabled: true
bot_token: "YOUR_BOT_TOKEN"
default_chat: "123456789"
parse_mode: "HTML" # 或 Markdown
发送消息示例
# 发送纯文本
openclaw message send --channel telegram --text "Hello!"
# 发送带格式的消息
openclaw message send --channel telegram \
--text "加粗 斜体 链接"
# 发送图片
openclaw message send --channel telegram \
--image "/path/to/image.png" \
--caption "图片说明"
💼 Slack配置
步骤1:创建Slack App
- 访问 Slack API
- 点击"Create New App" → "From scratch"
- 输入App名称,选择Workspace
- 在左侧菜单选择"OAuth & Permissions"
- 添加Scopes:chat:write, channels:read
- 点击"Install to Workspace"
- 复制"Bot User OAuth Token"
步骤2:OpenClaw配置
channels:
slack:
enabled: true
bot_token: "xoxb-your-token-here"
default_channel: "#general"
signing_secret: "optional-for-webhooks"
发送消息示例
# 发送到频道
openclaw message send \
--channel slack \
--to "#general" \
--text "团队通知测试"
# 发送给用户
openclaw message send \
--channel slack \
--to "@username" \
--text "私信测试"
# 发送富文本块
openclaw message send --channel slack --blocks '[
{
"type": "header",
"text": {"type": "plain_text", "text": "系统通知"}
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "*任务完成* ✅"}
}
]'
🔄 高级用法
消息模板
# 定义模板文件 templates/daily_report.md
## 📊 每日数据报告
- 新增用户:{{new_users}}
- 活跃用户:{{active_users}}
- 收入:{{revenue}}
生成时间:{{timestamp}}
# 使用模板发送
openclaw message send \
--channel discord \
--template templates/daily_report.md \
--vars '{"new_users": 100, "active_users": 500, "revenue": "$1000"}'
多平台同时发送
# 同时发送到Discord和Telegram
openclaw message broadcast \
--channels "discord,telegram,slack" \
--text "重要通知:系统维护时间今晚10点"
# JavaScript API
await message.broadcast({
channels: ['discord', 'telegram'],
content: '紧急通知!',
priority: 'high'
});
交互式消息
# Discord按钮
openclaw message send --channel discord \
--text "请选择操作:" \
--components '[
{
"type": 1,
"components": [
{"type": 2, "label": "确认", "style": 1, "custom_id": "confirm"},
{"type": 2, "label": "取消", "style": 4, "custom_id": "cancel"}
]
}
]'
✅ 最佳实践
- Token保密 - 不要将Token提交到Git仓库
- 权限最小化 - 只申请必要的权限
- 错误处理 - 添加消息发送失败的重试逻辑
- 消息分组 - 相关消息使用thread回复
- 频率限制 - 注意各平台的API调用限制
- 监控日志 - 记录消息发送状态便于排查