cc-haha/docs/im/dingtalk.md
程序员阿江(Relakkes) f1c5f86b80 feat: keep IM permission approvals consistent
DingTalk can receive interactive card callbacks, but the card UI still depends on a published template, so the adapter now supports a template-backed card path with text commands as the reliable fallback. Telegram and WeChat use the same allow-once, allow-always, and deny semantics so manual authorization behaves the same across platforms.

Constraint: DingTalk button rendering requires an operator-provided interactive card template id
Rejected: Treat the existing AI streaming card template as a permission card | it cannot guarantee visible action buttons
Confidence: high
Scope-risk: moderate
Directive: Do not remove the text approval fallback unless DingTalk card template provisioning is guaranteed
Tested: bun test adapters/common/__tests__/permission.test.ts adapters/dingtalk/__tests__/permission-card.test.ts adapters/telegram/__tests__/telegram.test.ts adapters/common/__tests__/config.test.ts src/server/__tests__/adapters.test.ts
Tested: bunx tsc -p adapters/tsconfig.json --noEmit
Tested: bun run check:adapters
Tested: cd desktop && bun run build
Tested: bun run check:server
Tested: bun run check:docs
Tested: git diff --check
Not-tested: bun run quality:pr is blocked by existing CLI core approval policy; see artifacts/quality-runs/2026-05-03T13-19-56-232Z/report.md
2026-05-04 19:03:36 +08:00

54 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 钉钉接入
钉钉接入走 DingTalk Stream不需要公网回调地址。桌面端设置页支持扫码创建并授权机器人授权成功后会把 `clientId / clientSecret` 写入 `~/.claude/adapters.json`
## 配置方式
打开 Desktop Webapp 的 `Settings -> IM 接入 -> 钉钉`
推荐方式:
1. 点击“扫码绑定”
2. 使用钉钉手机 App 扫码
3. 在钉钉里确认创建机器人
4. 等待桌面端显示已绑定
如果扫码不可用,也可以手动填写:
- `Client ID`
- `Client Secret`
- 可选 `Stream Endpoint`
- 可选 `Allowed Users`
- 可选 `权限卡片模板 ID`
## 配对用户
钉钉机器人绑定完成后,还需要让具体用户通过 IM 配对码授权:
1.`配对管理` 里生成配对码
2. 在钉钉私聊里把配对码发给机器人
3. 显示配对成功后即可开始聊天
配对用户会出现在“已配对用户”列表里,可以随时解绑。解绑后该用户需要重新发送新的配对码才能使用。
## 运行 adapter
桌面端发布版会通过 sidecar 自动启动。开发时可以手动运行:
```bash
cd adapters
bun install
bun run dingtalk
```
## 当前行为
- 只处理钉钉单聊消息
- 使用 `sessionWebhook` 回复文本 / Markdown
- 支持用户图片附件进入模型输入
- 支持 AI Card 流式输出和 thinking / 输入状态展示
- 支持 `/new``/projects``/status``/clear``/stop``/help`
- 权限确认支持 `/allow <requestId>``/always <requestId>``/deny <requestId>` 文本回复
- 如果配置了已发布的钉钉互动卡片模板 ID会优先发送权限卡片并通过 DingTalk Stream 的 `/v1.0/card/instances/callback` 接收按钮回调;卡片发送失败时自动回退到文本命令
- 群聊后续再扩展