mirror of
https://github.com/NanmiCoder/claude-code-haha.git
synced 2026-10-10 11:53:10 +08:00
feat(im): add scan-to-create Feishu bots plus WeCom, QQ and Slack adapters
Connecting Feishu meant creating a bot by hand on the open platform and pasting an App ID and App Secret back. Feishu also exposes an RFC 8628 device-authorization flow, so the desktop can now render a QR code, and confirming it in the app creates the bot and stores its credentials directly. `adapters/feishu/registration.ts` implements that protocol rather than importing `registerApp` from `@larksuiteoapi/node-sdk@1.73`: the repository pins 1.60 for the chat client, and the SDK runs the whole poll inside one un-cancellable promise where the desktop needs the stateless begin/poll pair the DingTalk registration already uses. The scan is create-only, so it can never rewrite the configuration of a bot the user already runs, and it pre-fills exactly the scopes, events and callbacks this adapter calls. International tenants finish on Lark's domain, which is now persisted and honoured by the client. WeCom, QQ and Slack join the same session model. WeCom and QQ bind by scanning; Slack has no scan flow, so it uses an app manifest that pre-fills the scopes and Socket Mode. All three run over long connections, so no public callback URL is needed, and all three accept private chats only — pairing authorizes one person, and answering in a group would extend that authorization to everyone else in the room. They are built on a new `adapters/common/chat-runtime.ts` instead of a fourth copy of the loop the five existing adapters each carry. A platform supplies a `ChatPort` — how to say something, how to open a streaming reply, optionally how to send an image — and the runtime owns pairing, command routing, session restore, permission bookkeeping and the translation of the server's stream. The existing five are deliberately left on their own copies; migrating them is a separate change with its own regression surface. Attachments are downloaded through a deferred loader that runs after the pairing gate and inside the per-chat queue. Resolving them eagerly would let an unpaired stranger make the adapter fetch bytes and write them under ~/.claude/im-downloads — on Slack with the bot token attached — and would let a slow attachment overtake a text message sent after it. The sidecar launcher's per-adapter branches become one table. It is declared above the mode dispatch on purpose: `runAdapters` is hoisted and runs at module top level, so a table declared below it is still in its temporal dead zone when the adapters mode reads it — which type checks, lints and unit tests all miss, and only the compiled binary reveals. Verified with the checks `check:impact` selects: adapters, server, desktop, electron, policy, chat-contract, agent-flow, docs, native (sidecar compile, packaging and an adapters-mode smoke against the real binary) and coverage. The scan flows themselves are not verified against live platforms — that needs real WeCom, QQ and Slack accounts and would create real bots. Claude-Session: https://claude.ai/code/session_01CCGoP316AK7wdQG3Ms6Uwq
This commit is contained in:
+27
-8
@@ -1,17 +1,30 @@
|
||||
---
|
||||
title: 飞书接入
|
||||
nav_title: 飞书
|
||||
description: 用官方模板一键创建飞书机器人,在飞书单聊里驱动桌面端并用卡片批权限。
|
||||
description: 在设置页扫码直接创建飞书机器人,在飞书单聊里驱动桌面端并用卡片批权限。
|
||||
order: 1
|
||||
---
|
||||
|
||||
# 飞书接入
|
||||
|
||||
适合国内团队:飞书官方给了一个权限预配好的模板机器人,点几下就能建出来,权限审批是可点的交互卡片,还能把常用命令做成机器人菜单。限制是只处理单聊(`p2p`),不处理群聊;改机器人配置要回开放平台发一次新版本。
|
||||
适合国内团队:在桌面端点一下扫码,用飞书扫一扫就把机器人建出来,App ID 和 App Secret 自动写进本机配置。权限审批是可点的交互卡片,还能把常用命令做成机器人菜单。限制是只处理单聊(`p2p`),不处理群聊;改机器人菜单要回开放平台发一次新版本。
|
||||
|
||||
## 一键创建机器人
|
||||
## 扫码创建机器人
|
||||
|
||||
打开[创建飞书机器人](https://open.feishu.cn/page/openclaw?form=multiAgent)。这是官方为 OpenClaw 预配好消息、事件订阅、卡片回调等全部权限的模板,不需要再手动加 scope。桌面端「设置」→「IM 接入」→「飞书」里的「一键创建飞书机器人」按钮打开的也是这个页面。
|
||||
1. 打开「设置」→「IM 接入」,切到「飞书」Tab。
|
||||
2. 点「扫码创建」,页面上会出现一张二维码。
|
||||
3. 用飞书扫码。确认页上会预填好机器人的名字、说明,以及这个适配器真正会用到的权限、事件订阅和卡片回调——不多申请一项。
|
||||
4. 确认后 App ID 和 App Secret 会自动写入 `~/.claude/adapters.json`,适配器随即重启。
|
||||
|
||||
二维码 10 分钟内有效,过期后点一下重新生成。绑定成功后按钮变成「重新扫码」,旁边多一个「解除机器人绑定」。
|
||||
|
||||
扫码只会**新建**机器人,不会绑定你已有的那一个——否则这个流程可能悄悄改掉你在跑的机器人的回调配置。
|
||||
|
||||
「Encrypt Key」和「Verification Token」留空即可:消息走 WebSocket 长连接,用不到这两个值。
|
||||
|
||||
::: tip 也可以手动创建
|
||||
不想扫码,或者要复用已有机器人,就用[官方 OpenClaw 模板](https://open.feishu.cn/page/openclaw?form=multiAgent)建一个,再把 App ID 和 App Secret 填进「飞书」Tab 下方的输入框。桌面端在没有凭据时也会显示这个入口。
|
||||
:::
|
||||
|
||||

|
||||
|
||||
@@ -49,11 +62,13 @@ order: 1
|
||||
|
||||

|
||||
|
||||
## 在桌面端填凭据
|
||||
## 手动填凭据
|
||||
|
||||
扫码创建的机器人不需要这一步——凭据已经写好了。只有用模板手动创建、或者要复用已有机器人时才需要:
|
||||
|
||||
1. 打开「设置」→「IM 接入」,切到「飞书」Tab。
|
||||
2. 把上一步的 App ID 和 App Secret 填进「App ID」和「App Secret」。
|
||||
3. 「Encrypt Key」和「Verification Token」留空即可,模板机器人不需要。
|
||||
2. 把 App ID 和 App Secret 填进「App ID」和「App Secret」。
|
||||
3. 「Encrypt Key」和「Verification Token」留空即可,长连接模式不需要。
|
||||
4. 需要长时间流式更新同一张卡片时,勾上「流式卡片模式」。
|
||||
5. 点「保存」。
|
||||
|
||||
@@ -114,6 +129,10 @@ export ADAPTER_SERVER_URL="ws://127.0.0.1:3456"
|
||||
|
||||
## 常见问题
|
||||
|
||||
**二维码扫了没反应**:扫码走 `accounts.feishu.cn`,确认本机能访问。国际版租户(Lark)在确认后会自动切到 `accounts.larksuite.com` 完成,不用手动切换。
|
||||
|
||||
**扫完提示已过期**:二维码 10 分钟有效,点「重新扫码」再生成一张。
|
||||
|
||||
**收不到消息**:确认机器人已发布(改过菜单要重新「创建新版本并发布」),以及聊天窗口是和机器人的单聊而不是群。
|
||||
|
||||
**权限卡片点了没反应**:一般是卡片回调能力没随版本发布,回开放平台重新发一次版本。
|
||||
@@ -124,4 +143,4 @@ export ADAPTER_SERVER_URL="ws://127.0.0.1:3456"
|
||||
|
||||
## 源码入口
|
||||
|
||||
`adapters/feishu/index.ts`,以及 `adapters/common/` 下的 `pairing.ts`、`session-store.ts`、`ws-bridge.ts`、`http-client.ts`。
|
||||
`adapters/feishu/index.ts`(运行时)、`adapters/feishu/registration.ts`(扫码创建),以及 `adapters/common/` 下的 `pairing.ts`、`session-store.ts`、`ws-bridge.ts`、`http-client.ts`。
|
||||
|
||||
Reference in New Issue
Block a user