feat(s04): 飞书新增长连接 (WebSocket) 入站模式 - #17
Draft
sfenga wants to merge 1 commit into
Draft
Conversation
FeishuChannel 原本只有 webhook 入站思路且未内置 HTTP 服务, 本变更新增
lark-oapi 长连接模式 (默认): SDK 主动向飞书发起出站 WebSocket, 无需公网
域名/加密策略/challenge 握手, 本地即可跑通入站.
- FeishuChannel 新增 parse_ws_event() 解析 P2ImMessageReceiveV1 事件为
InboundMessage (复用 _parse_content; 注意 ws 事件字段为 message_type
而非 msg_type), 与 parse_event 同形不同源.
- 新增 _ws_bot_mentioned() 检查群聊 @机器人 (mention.id.open_id).
- 新增 start_long_connection(): 守护线程跑 lark.ws.Client (auto_reconnect),
事件塞入与 Telegram/CLI 共用的 msg_queue, agent 循环无需改动.
- FEISHU_MODE=ws|webhook 开关 (默认 ws); 修正 .env.example 中已与代码
不同步的 FEISHU_DOMAIN (实际用 FEISHU_IS_LARK), 补全 ENCRYPT_KEY/
BOT_OPEN_ID/MODE 说明.
- requirements.txt 增加 lark-oapi>=1.7.0 (惰性导入, 可选).
- 三语 (en/zh/ja) s04_channels.py + .md 同步.
- 排空循环标签由硬编码 [telegram] 改为 [{m.channel}] (飞书消息现在共用队列).
非破坏性: 不设 FEISHU_MODE 或未装 lark-oapi 时退回原有 webhook 解析路径,
现有出站 send() 行为不变.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
FeishuChannel原本只有 webhook 入站思路且未内置 HTTP 服务(入站实际跑不通)。本变更新增 lark-oapi 长连接 (WebSocket) 模式(默认):SDK 主动向飞书发起出站 WebSocket,无需公网域名 / 加密策略 / challenge 握手,本地python sessions/zh/s04_channels.py即可收飞书消息。Why
飞书开放平台现在主推长连接,本地开发零配置(对比 webhook 需 ngrok 穿透 + 加密策略)。更贴合 claw0 「
python xx.py就能跑」的教学哲学。Changes
FeishuChannel.parse_ws_event():解析P2ImMessageReceiveV1事件为InboundMessage(复用_parse_content;注意 ws 事件字段为message_type而非msg_type),与parse_event同形不同源。_ws_bot_mentioned():群聊检查mention.id.open_id == bot_open_id。start_long_connection():守护线程跑lark.ws.Client(auto_reconnect),事件塞入与 Telegram / CLI 共用的msg_queue,agent 循环零改动。FEISHU_MODE=ws|webhook开关(默认ws)。.env.example中已与代码不同步的FEISHU_DOMAIN(实际用FEISHU_IS_LARK),补全FEISHU_ENCRYPT_KEY/FEISHU_BOT_OPEN_ID/FEISHU_MODE说明。requirements.txt增加lark-oapi>=1.7.0(惰性导入,可选,与 httpx/websockets 一致)。[telegram]→[{m.channel}](飞书消息现在与 Telegram 共用队列)。s04_channels.py+.md同步。Non-breaking
不设
FEISHU_MODE或未装lark-oapi时,退回原有 webhook 解析路径;现有出站send()行为不变。Verified
py_compile通过。P2ImMessageReceiveV1payload 测试parse_ws_event:p2p 文本、群聊无 @过滤 / 有 @通过、post 富文本、image 媒体均正确。lark.ws.Client正常拨号,假凭证得到真实鉴权错误(app_id is invalid),无 asyncio loop 冲突。How to use
```sh
pip install lark-oapi
.env
FEISHU_APP_ID=cli_xxxxxxxx
FEISHU_APP_SECRET=xxxxxxxx
飞书开放平台 → 事件订阅 → 选「长连接」模式
python sessions/zh/s04_channels.py
```