Skip to content

飞书 Claude 集成#1

Merged
lishuceo merged 9 commits into
mainfrom
cursor/claude-9f78
Feb 17, 2026
Merged

飞书 Claude 集成#1
lishuceo merged 9 commits into
mainfrom
cursor/claude-9f78

Conversation

@lishuceo
Copy link
Copy Markdown
Owner

Initialize project structure and create core code skeleton for the Feishu-Claude Code bridge server.


Open in Cursor Open in Web

- 设计完整的系统架构方案 (README.md)
- 项目初始化: package.json, tsconfig.json, .env.example
- 飞书模块: 事件处理、API 客户端、消息卡片构建器
- Claude Code 模块: CLI 执行器、输出解析器
- 会话管理: 会话管理器、任务队列
- 工具模块: 日志、安全检查
- Express HTTP 服务器: webhook 回调处理

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 14, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 4 commits February 14, 2026 05:41
- ClaudeExecutor 重构为长连接会话模式 (ClaudeSession)
  - 使用 --input-format stream-json --output-format stream-json
  - 每个飞书会话对应一个持久的 Claude Code 子进程
  - 多轮对话上下文由进程自然维护,无需 --resume
  - 支持流式事件回调 (进度更新)
- 更新 event-handler 适配新接口
  - /reset 命令同时终止 Claude Code 进程
  - /stop 命令只终止当前会话进程
- 更新 README 调用方式说明,移除不存在的 SDK import 方式
- 移除 CLAUDE_MODE 配置项

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
… 子进程

核心变更:
- 引入 @anthropic-ai/claude-agent-sdk 作为核心依赖
- ClaudeExecutor 使用 SDK 的 query() API 替代 spawn CLI 子进程
  - 完整 TypeScript 类型支持
  - SDK 自动管理工具执行、权限
  - 通过 resume option 实现会话续接
  - 通过 query.close() 实现中断
  - 自动追踪花费 (total_cost_usd)
- 项目改为 ESM (package.json type:module, tsconfig module:ES2022)
- 移除 @anthropic-ai/claude-code (CLI 包), 新增 zod (peer dep)
- 移除不再需要的 claude/output-parser.ts
- 更新 README 文档全面反映 Agent SDK 用法
- 所有 import 路径添加 .js 后缀 (ESM 规范)

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
- 用 lark.EventDispatcher 替代手写的 challenge 验证、事件去重、签名校验
  - SDK 自动处理 URL verification、事件加密解密、去重缓存
  - 类型安全的 'im.message.receive_v1' 事件注册
- 用 lark.adaptExpress() 一行代码接入 Express 路由
- 用 lark.CardActionHandler 处理卡片交互回调
- 删除 feishu/types.ts (手写类型不再需要,SDK 提供完整类型)
- server.ts 大幅简化,不再手动处理 challenge/错误

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
将快速开始扩充为完整的 5 步部署指南:
- 第1步: 飞书开放平台创建应用 (8 个子步骤)
  - 创建应用、记录凭证、开启机器人能力
  - 配置权限 (6 项权限详解)
  - 配置事件订阅 (Webhook / WebSocket 两种方式)
  - 发布应用、验证机器人
- 第2步: 准备服务器环境 (Node.js + API Key)
- 第3步: 部署本项目 (克隆、安装、配置、启动)
- 第4步: 配置网络 (ngrok / nginx / PM2 三种方案)
- 第5步: 验证 + 常见问题排查表

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
@lishuceo lishuceo marked this pull request as ready for review February 14, 2026 07:33
cursoragent and others added 4 commits February 14, 2026 07:42
问题修正:
- 权限表中 im:message:send_as_bot 重复列出两行
  - 发消息权限: im:message:send_as_bot (create/reply)
  - 更新卡片权限: im:message:patch_as_bot (patch)
  - 两个是不同的权限,分别说明

新增 WebSocket 模式 (FEISHU_EVENT_MODE=websocket):
- 使用飞书 SDK 的 WSClient 主动连接飞书
- 无需公网 IP、无需 HTTPS、无需配置回调地址
- 适合开发调试和内网部署场景
- server.ts 支持 webhook/websocket 两种模式自动切换

文档改进:
- 1.6 事件订阅章节完全重写
  - 两种方式分别写出完整步骤
  - webhook 模式明确说明先后顺序 (先部署再配地址)
  - 添加两种方式的对比表
- .env.example 默认改为 websocket 模式 (降低上手门槛)

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
- 1.6 事件订阅大幅简化: 选「长连接」→ 加事件 → 完成
  无需回调 URL、无需 Encrypt Key、无需公网
- .env.example: 默认只需 APP_ID + APP_SECRET + API_KEY 三项
  webhook 相关配置标注为仅 webhook 模式需要
- 第四步: 去掉 ngrok/nginx 等网络配置 (websocket 不需要)
  只保留 PM2 进程守护作为可选生产部署
- 部署方案环境变量列表: 区分必填/可选
- HTTP Webhook 完整步骤移入文末附录

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
根据飞书后台实际显示的权限名修正,之前是凭推测写的错误标识。
同时精简权限说明,去掉冗余注释。

Co-authored-by: unclee <lishuceo@users.noreply.github.com>
- 每个用户会话自动创建飞书话题(thread),所有回复在话题内进行
- 切换 executor 权限模式: bypassPermissions → acceptEdits + canUseTool 回调 (兼容 root 用户)
- 自动创建工作目录,清除嵌套检测环境变量
- 添加消息去重缓存,防止飞书重试导致重复处理
- 默认事件模式改为 websocket
- 添加 CLAUDE.md 项目文档

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants