CoPaw 频道配置详解
CoPaw 频道配置详解
CoPaw 支持多种交互频道,让你可以在不同的平台和环境中与 AI 助手进行交互。本文将详细介绍如何配置和使用各种频道,包括控制台、Slack、Discord、Telegram、企业微信、飞书等。
频道概述
支持的频道类型
CoPaw 支持以下交互频道:
| 频道类型 | 描述 | 适用场景 |
|---------|------|---------|
| 控制台 | 命令行界面 | 开发者、技术用户 |
| Slack | 企业协作平台 | 团队协作、工作集成 |
| Discord | 游戏社区平台 | 社区管理、游戏相关 |
| Telegram | 即时通讯工具 | 个人使用、快速交流 |
| 企业微信 | 企业通讯工具 | 企业内部使用 |
| 飞书 | 企业协作平台 | 企业内部使用 |
| HTTP Webhook | 自定义接口 | 集成到自定义系统 |
频道特性对比
| 特性 | 控制台 | Slack | Discord | Telegram |
|------|-------|-------|---------|----------|
| 代码高亮 | ✅ | ⚠️ | ✅ | ⚠️ |
| 文件传输 | ✅ | ✅ | ✅ | ✅ |
| 群组支持 | ❌ | ✅ | ✅ | ✅ |
| 机器人 | N/A | ✅ | ✅ | ✅ |
| Webhook | ❌ | ✅ | ✅ | ✅ |
| 实时消息 | ✅ | ✅ | ✅ | ✅ |
控制台频道
控制台是 CoPaw 的默认交互方式,已经在第一篇教程中详细介绍过。这里简要说明配置方法。
配置文件
{
"channels": {
"console": {
"enabled": true,
"history_size": 1000,
"autosave": true,
"color_output": true
}
}
}
启动控制台
# 基本启动
copaw console
# 指定工作目录
copaw console --workdir /path/to/copaw
# 调试模式
copaw console --debug
Slack 频道配置
获取 Bot Token
- 访问 Slack API
- 点击 "Create New App"
- 选择 "From scratch"
- 填写 App 名称和工作空间
- 进入 "OAuth & Permissions"
- 在 "Bot Token Scopes" 中添加以下权限:
chat:write- 发送消息chat:write.customize- 自定义消息files:write- 上传文件channels:history- 读取频道历史groups:history- 读取群组历史im:history- 读取私信历史
7. 滚动到 "OAuth Tokens for Your Workspace"
- 点击 "Install to Workspace"
- 复制生成的 "Bot User OAuth Token"
配置 Slack
编辑配置文件:
{
"channels": {
"slack": {
"enabled": true,
"bot_token": "xoxb-xxxxxxxxxxxxxxxxxxxxxxxx",
"signing_secret": "xxxxxxxxxxxxxxxxxxxxxxxx",
"app_id": "A1234567890",
"channels": [
{
"name": "general",
"id": "C1234567890",
"type": "channel"
},
{
"name": "copaw-dev",
"id": "D1234567890",
"type": "dm"
}
]
}
}
}
通过控制台配置
# 启用 Slack 频道
/config set channels.slack.enabled true
# 设置 Bot Token
/config set channels.slack.bot_token xoxb-xxxxxxxxxxxxxxxx
# 设置 Signing Secret
/config set channels.slack.signing_secret xxxxxxxxxxxxxxxxxxxxxxxx
# 设置 App ID
/config set channels.slack.app_id A1234567890
# 添加频道
/config set channels.slack.channels.[0].name general
/config set channels.slack.channels.[0].id C1234567890
/config set channels.slack.channels.[0].type channel
# 保存配置
/config save
邀请 Bot 到频道
- 在 Slack 中打开已创建的 App
- 进入 "Install App" 页面
- 找到你的 App
- 点击 "Add to Slack"
- 选择要添加的频道
- 点击 "Allow"
测试 Slack 频道
# 测试连接
/channel test slack
# 发送测试消息
/channel send slack "Hello from CoPaw!"
Slack 高级配置
{
"channels": {
"slack": {
"enabled": true,
"bot_token": "xoxb-xxxxxxxxxxxxxxxx",
"signing_secret": "xxxxxxxxxxxxxxxx",
"app_id": "A1234567890",
"channels": [
{
"name": "general",
"id": "C1234567890",
"type": "channel",
"mention": "@copaw"
}
],
"webhook_url": "https://hooks.slack.com/services/xxx/xxx/xxx",
"notification": {
"enabled": true,
"channel": "#notifications"
}
}
}
}
Discord 频道配置
创建 Discord Bot
- 访问 Discord Developer Portal
- 点击 "New Application"
- 填写 App 名称
- 点击 "Create"
- 在左侧菜单点击 "Bot"
- 点击 "Add Bot"
- 确认创建
获取 Bot Token
- 在 "Bot" 页面
- 找到 "Token" 部分
- 点击 "Reset Token"
- 复制生成的 Token
配置 Bot 权限
- 在左侧菜单点击 "OAuth2" -> "URL Generator"
- 在 "Scopes" 中勾选:
bot
3. 在 "Bot Permissions" 中勾选:
Send MessagesSend Messages in ThreadsEmbed LinksAttach FilesRead Message HistoryAdd ReactionsUse Slash Commands
4. 复制生成的 URL
- 在浏览器中打开 URL
- 选择服务器并授权
配置 Discord
{
"channels": {
"discord": {
"enabled": true,
"bot_token": "MTIzNDU2Nzg5MA.GhIjKl.MnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUv",
"client_id": "1234567890",
"client_secret": "xxxxxxxxxxxxxxxx",
"guild_id": "9876543210",
"channels": [
{
"name": "general",
"id": "123456789012345678",
"type": "text"
},
{
"name": "copaw",
"id": "123456789012345679",
"type": "text"
}
]
}
}
}
通过控制台配置
# 启用 Discord 频道
/config set channels.discord.enabled true
# 设置 Bot Token
/config set channels.discord.bot_token MTIzNDU2Nzg5MA.GhIjKl.MnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUv
# 设置 Client ID
/config set channels.discord.client_id 1234567890
# 设置 Client Secret
/config set channels.discord.client_secret xxxxxxxxxxxxxxxx
# 设置 Guild ID
/config set channels.discord.guild_id 9876543210
# 保存配置
/config save
添加 Slash 命令
# 添加帮助命令
/discord slash add help "显示帮助信息"
# 添加配置命令
/discord slash add config "配置 CoPaw"
# 添加状态命令
/discord slash add status "查看 CoPaw 状态"
测试 Discord 频道
# 测试连接
/channel test discord
# 发送测试消息
/channel send discord "Hello from CoPaw!"
Telegram 频道配置
创建 Telegram Bot
- 在 Telegram 中搜索 @BotFather
- 发送
/newbot - 按提示输入 Bot 名称
- 按提示输入 Bot 用户名(必须以
bot结尾) - 复制生成的 API Token
配置 Telegram
{
"channels": {
"telegram": {
"enabled": true,
"bot_token": "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz",
"channels": [
{
"name": "个人",
"id": 123456789,
"type": "private"
},
{
"name": "测试群组",
"id": -1001234567890,
"type": "group"
}
]
}
}
}
获取频道 ID
# 获取个人 ID
/channel telegram get-id
# 获取群组 ID
1. 将 Bot 添加到群组
2. 在群组中发送 /start
3. 查看 CoPaw 日志,找到 group ID
通过控制台配置
# 启用 Telegram 频道
/config set channels.telegram.enabled true
# 设置 Bot Token
/config set channels.telegram.bot_token 1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
# 添加个人频道
/config set channels.telegram.channels.[0].name 个人
/config set channels.telegram.channels.[0].id 123456789
/config set channels.telegram.channels.[0].type private
# 保存配置
/config save
启动 Bot
# 启动 Telegram Bot
/channel telegram start
# 查看状态
/channel telegram status
设置 Webhook
# 设置 Webhook(需要公网地址)
/channel telegram webhook set https://your-domain.com/webhook/telegram
# 查看 Webhook 信息
/channel telegram webhook info
# 删除 Webhook
/channel telegram webhook delete
测试 Telegram 频道
# 测试连接
/channel test telegram
# 发送测试消息
/channel send telegram "Hello from CoPaw!"
企业微信频道配置
创建企业应用
- 访问 企业微信管理后台
- 进入 "应用管理"
- 点击 "创建应用"
- 填写应用信息
- 创建完成后进入应用详情页
- 记录以下信息:
- AgentId
- Secret
- 企业 ID(CorpId)
配置企业微信
{
"channels": {
"wecom": {
"enabled": true,
"corp_id": "ww1234567890abcdef",
"agent_id": "1000001",
"secret": "xxxxxxxxxxxxxxxx",
"encoding_aes_key": "xxxxxxxxxxxxxxxx",
"token": "xxxxxxxxxxxxxxxx",
"channels": [
{
"name": "内部群",
"id": "1234567890abcdef1234567890",
"type": "group"
},
{
"name": "测试用户",
"id": "User001",
"type": "user"
}
]
}
}
}
通过控制台配置
# 启用企业微信频道
/config set channels.wecom.enabled true
# 设置企业 ID
/config set channels.wecom.corp_id ww1234567890abcdef
# 设置 Agent ID
/config set channels.wecom.agent_id 1000001
# 设置 Secret
/config set channels.wecom.secret xxxxxxxxxxxxxxxx
# 设置 Token
/config set channels.wecom.token xxxxxxxxxxxxxxxx
# 保存配置
/config save
配置接收消息
- 在企业微信管理后台,进入应用详情页
- 点击 "接收消息"
- 设置接收消息的 URL(需要公网地址)
- 生成 EncodingAESKey 和 Token
- 保存配置
测试企业微信频道
# 测试连接
/channel test wecom
# 发送测试消息
/channel send wecom "Hello from CoPaw!"
飞书频道配置
创建飞书应用
- 访问 飞书开放平台
- 进入 "应用管理"
- 点击 "创建企业自建应用"
- 填写应用信息
- 创建完成后进入应用详情页
- 记录以下信息:
- App ID
- App Secret
配置飞书
{
"channels": {
"feishu": {
"enabled": true,
"app_id": "cli_a1b2c3d4e5f6",
"app_secret": "xxxxxxxxxxxxxxxx",
"encrypt_key": "xxxxxxxxxxxxxxxx",
"verification_token": "xxxxxxxxxxxxxxxx",
"channels": [
{
"name": "内部群",
"id": "ou_xxxxxxxxxxxxxxxxxxxxxxxx",
"type": "group"
},
{
"name": "测试用户",
"id": "ou_xxxxxxxxxxxxxxxxxxxxxxxx",
"type": "user"
}
]
}
}
}
配置权限
在飞书开放平台配置以下权限:
im:message- 发送消息im:message:group_at_msg- 群组消息im:chat- 聊天contact:user.base:readonly- 读取用户信息
通过控制台配置
# 启用飞书频道
/config set channels.feishu.enabled true
# 设置 App ID
/config set channels.feishu.app_id cli_a1b2c3d4e5f6
# 设置 App Secret
/config set channels.feishu.app_secret xxxxxxxxxxxxxxxx
# 保存配置
/config save
测试飞书频道
# 测试连接
/channel test feishu
# 发送测试消息
/channel send feishu "Hello from CoPaw!"
HTTP Webhook 频道
配置 Webhook
{
"channels": {
"webhook": {
"enabled": true,
"endpoints": [
{
"name": "自定义系统",
"url": "https://your-domain.com/api/webhook",
"auth": {
"type": "bearer",
"token": "xxxxxxxxxxxxxxxx"
}
}
]
}
}
}
通过控制台配置
# 启用 Webhook 频道
/config set channels.webhook.enabled true
# 添加端点
/config set channels.webhook.endpoints.[0].name 自定义系统
/config set channels.webhook.endpoints.[0].url https://your-domain.com/api/webhook
/config set channels.webhook.endpoints.[0].auth.type bearer
/config set channels.webhook.endpoints.[0].auth.token xxxxxxxxxxxxxxxx
# 保存配置
/config save
测试 Webhook
# 测试连接
/channel test webhook
# 发送测试消息
/channel send webhook '{"text":"Hello from CoPaw!"}'
频道管理
查看所有频道
/channel list
测试频道
/channel test <频道类型>
启用/禁用频道
# 启用频道
/channel enable <频道类型>
# 禁用频道
/channel disable <频道类型>
查看频道状态
/channel status <频道类型>
发送消息到频道
/channel send <频道类型> <消息>
多频道策略
频道优先级
在配置文件中定义频道优先级:
{
"channels": {
"priority": [
"console",
"slack",
"telegram"
],
"console": {
"enabled": true
},
"slack": {
"enabled": true
},
"telegram": {
"enabled": true
}
}
}
根据上下文选择频道
在 AGENTS.md 中定义:
# 频道选择策略
## 工作时间
优先使用:Slack
备用:控制台
## 个人时间
优先使用:Telegram
备用:控制台
## 紧急情况
使用所有启用的频道
常见问题
Q1: Slack Bot 无法接收消息?
检查以下几点:
- Bot 是否已添加到频道
- Bot 是否有足够的权限
- Webhook URL 是否正确配置
- Event Subscriptions 是否正确设置
# 检查 Bot 权限
/channel check slack permissions
# 检查 Webhook
/channel check slack webhook
Q2: Discord Bot 无法响应命令?
可能的原因:
- Slash 命令未注册
- Bot 没有足够的权限
- 命令冷却时间
# 重新注册 Slash 命令
/discord slash register --all
# 检查权限
/channel check discord permissions
Q3: Telegram Bot 不工作?
检查步骤:
- Bot Token 是否正确
- Bot 是否已启动
- 用户 ID 是否正确
- Webhook 是否正确设置
# 检查 Bot 状态
/channel telegram status
# 重启 Bot
/channel telegram restart
Q4: 企业微信消息发送失败?
检查以下配置:
- CorpId、AgentId、Secret 是否正确
- 应用是否有发送消息权限
- 用户 ID 是否正确
# 测试企业微信连接
/channel test wecom
# 查看详细日志
/channel wecom debug
Q5: 如何实现跨频道同步?
# 启用跨频道同步
/config set channels.sync.enabled true
# 设置同步的频道
/config set channels.sync.channels ["slack", "telegram", "feishu"]
# 保存配置
/config save
最佳实践
1. 根据用途选择频道
开发调试 → 控制台
团队协作 → Slack
社区互动 → Discord
个人使用 → Telegram
企业内部 → 企业微信/飞书
系统集成 → HTTP Webhook
2. 设置合理的消息历史
# 设置消息历史大小
/config set channels.slack.history_size 100
/config set channels.telegram.history_size 50
3. 启用消息过滤
# 启用垃圾消息过滤
/config set channels.filter.enabled true
/config set channels.filter.keywords ["广告", "推广"]
4. 定期检查频道状态
# 定期检查所有频道
/channel check all
# 查看频道统计
/channel stats
5. 配置通知频道
# 设置重要通知频道
/config set channels.notification.slack #alerts
/config set channels.notification.telegram @important_user
总结
通过本教程,你应该已经掌握了:
- ✅ 各种频道的配置方法
- ✅ Bot Token 和权限的获取
- ✅ 多频道管理和切换
- ✅ 频道测试和调试
- ✅ 跨频道同步
- ✅ 常见问题排查
下一章
在下一章中,我们将学习 CoPaw Skills 系统详解,了解如何使用和管理各种技能,包括内置技能和自定义技能。







