我来详细分析这两种交互方式的差异。让我先查看相关源码:
让我继续查看飞书插件中更多的核心处理逻辑:
现在让我查看飞书如何处理消息并调用 Agent:
让我继续查看飞书消息处理的核心部分,特别是如何调用 Agent:
现在让我继续查看飞书如何触发 Agent 调用:
现在我有了完整的信息,可以为你做一个详细的对比了:
OpenAI HTTP API vs 飞书渠道 功能详细对比
一、整体架构对比
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| ┌─────────────────────────────────────────────────────────────────────────────┐ │ OpenAI HTTP API (openai-http.ts) │ ├─────────────────────────────────────────────────────────────────────────────┤ │ PC App / IDE ────HTTP POST───▶ Gateway ────agentCommand()───▶ Agent │ │ │ │ 特点: 简单、无状态、客户端管理历史 │ └─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐ │ 飞书渠道 (extensions/feishu/) │ ├─────────────────────────────────────────────────────────────────────────────┤ │ 飞书App ────WebSocket───▶ Plugin ──处理──▶ 路由 ──▶ dispatchReplyFromConfig │ │ │ │ │ │ ▼ ▼ │ │ 丰富的中间处理层 自动回复/打字指示器 │ │ │ │ 特点: 全功能、服务端管理、自动路由、富媒体支持 │ └─────────────────────────────────────────────────────────────────────────────┘
|
二、功能特性对比表
| 功能维度 |
OpenAI HTTP API |
飞书渠道 |
| 协议 |
HTTP REST |
WebSocket 长连接 |
| 消息格式 |
OpenAI 标准格式 |
飞书私有格式 |
| 代码量 |
~380 行 |
~1200+ 行 |
1. 会话管理
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 会话历史 |
❌ 客户端携带 messages[] |
✅ 服务端自动管理 |
| 多轮对话 |
客户端维护 |
服务端自动 |
| 群聊历史 |
不支持 |
✅ chatHistories 记录非@消息 |
| 会话隔离 |
通过 user 参数 |
✅ 自动按用户/群组/话题 |
1 2 3 4 5 6 7
| const sessionKey = resolveOpenAiSessionKey({ req, agentId, user });
groupSessionScope = "group" | "group_sender" | "group_topic" | "group_topic_sender"
|
2. Agent 路由
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 路由方式 |
客户端指定 model |
✅ 服务端自动路由 |
| 使用 bindings |
❌ |
✅ |
| 动态创建 Agent |
❌ |
✅ maybeCreateDynamicAgent() |
| 基于用户/群组 |
❌ |
✅ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| const agentId = resolveAgentIdForRequest({ req, model });
const route = core.channel.routing.resolveAgentRoute({ cfg, channel: "feishu", accountId: account.accountId, peer: { kind: isGroup ? "group" : "direct", id: peerId, }, parentPeer: });
|
3. 消息处理
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 发送者身份 |
可选 user 参数 |
✅ 自动解析 sender_id |
| 发送者名称 |
❌ |
✅ resolveFeishuSenderName() |
| @提及检测 |
❌ |
✅ checkBotMentioned() |
| 消息去重 |
❌ |
✅ 内存 + 持久化去重 |
| 引用/回复消息 |
❌ |
✅ 获取被引用内容 |
| 合并转发消息 |
❌ |
✅ 解析展开 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| const prompt = buildAgentPrompt(payload.messages);
if (event.message.message_type === "merge_forward") { } if (ctx.parentId) { quotedContent = await getMessageFeishu(); } const messageBody = buildFeishuAgentBody({ ctx, quotedContent, permissionErrorForAgent, });
|
4. 媒体支持
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 图片 |
❌ |
✅ 下载并保存 |
| 文件 |
❌ |
✅ 各种类型 |
| 音视频 |
❌ |
✅ |
| 表情包 |
❌ |
✅ |
| 富文本(post) |
❌ |
✅ 解析嵌入媒体 |
1 2 3 4 5 6 7 8
| const mediaList = await resolveFeishuMediaList({ cfg, messageId: ctx.messageId, messageType: event.message.message_type, content: event.message.content, maxBytes: mediaMaxBytes, });
|
5. 访问控制
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 认证 |
Gateway Token |
✅ + 飞书 App 凭证 |
| 配对机制 |
❌ |
✅ dmPolicy: "pairing" |
| 白名单 |
❌ |
✅ allowFrom, groupAllowFrom |
| 群组策略 |
❌ |
✅ groupPolicy: "open"/"allowlist"/"disabled" |
| 命令权限 |
❌ |
✅ commandAuthorized |
1 2 3 4 5 6 7 8
| if (!isGroup && dmPolicy !== "open" && !dmAllowed) { if (dmPolicy === "pairing") { await sendMessageFeishu({ text: buildPairingReply(...) }); } return; }
|
6. 回复机制
| 特性 |
OpenAI HTTP API |
飞书渠道 |
| 流式响应 |
✅ SSE |
✅ 流式卡片 |
| 打字指示器 |
❌ |
✅ 表情反应 |
| Markdown 卡片 |
❌ |
✅ 自动检测并渲染 |
| @回复 |
❌ |
✅ 自动 @提及 |
| 线程回复 |
❌ |
✅ replyInThread |
1 2 3 4 5 6 7 8 9 10 11
| writeAssistantContentChunk(res, { content, finishReason });
const { dispatcher } = createFeishuReplyDispatcher({ chatId, replyToMessageId, replyInThread, mentionTargets, });
|
三、代码结构对比
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| openai-http.ts (~380行) ├── 请求解析 (buildAgentPrompt) ├── Agent 调用 (agentCommand) └── 响应格式化 (OpenAI 格式)
飞书插件 (~1200+行,多文件) ├── bot.ts - 主消息处理 ├── reply-dispatcher.ts - 回复分发 ├── streaming-card.ts - 流式卡片 ├── media.ts - 媒体处理 ├── policy.ts - 策略控制 ├── dynamic-agent.ts - 动态 Agent ├── typing.ts - 打字指示器 ├── mention.ts - @提及处理 └── ... 更多功能模块
|
四、调用链路对比
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| ┌─────────── OpenAI HTTP API 调用链 ───────────┐ │ │ │ POST /v1/chat/completions │ │ ↓ │ │ handleOpenAiHttpRequest() │ │ ↓ │ │ buildAgentPrompt(messages) │ │ ↓ │ │ agentCommand(input) ←── 直接调用 Agent │ │ ↓ │ │ 返回 OpenAI 格式响应 │ └───────────────────────────────────────────────┘
┌─────────── 飞书渠道调用链 ───────────────────┐ │ │ │ 飞书 WebSocket 消息 │ │ ↓ │ │ handleFeishuMessage() │ │ ↓ │ │ 去重 → 权限检查 → 解析消息 → 获取媒体 │ │ ↓ │ │ resolveAgentRoute() ←── 复杂路由 │ │ ↓ │ │ maybeCreateDynamicAgent() ←── 动态 Agent │ │ ↓ │ │ dispatchReplyFromConfig() ←── 统一分发 │ │ ↓ │ │ createFeishuReplyDispatcher() ←── 回复处理 │ │ ↓ │ │ 发送到飞书 (卡片/文本/媒体) │ └───────────────────────────────────────────────┘
|
五、总结
| 维度 |
OpenAI HTTP API |
飞书渠道 |
| 定位 |
通用 API 接口 |
完整 IM 集成 |
| 复杂度 |
简单 |
复杂 |
| 适用场景 |
IDE/自定义客户端 |
飞书用户聊天 |
| 扩展性 |
需客户端实现 |
服务端全托管 |
| 会话管理 |
客户端负责 |
服务端自动 |
| 媒体/富文本 |
不支持 |
完整支持 |
| 访问控制 |
仅 Token |
多层策略 |
简而言之:
- OpenAI HTTP API 是一个轻量级兼容层,让标准客户端能够使用 OpenClaw
- 飞书渠道是一个完整的 IM 集成方案,提供企业级的消息处理、权限控制、媒体支持等功能