feat: 新增 Discord 渠道接入 - #82
Open
aurevian-biz wants to merge 15 commits into
Open
Conversation
- SUPPORTED_CHANNELS/CHANNEL_META 增加 discord 条目 - channels/__init__.py 注册 DiscordStreamManager 单例与启停 - service_identity 增加 discord 标签与账号稳定键 - service_intake 将 discord 纳入 durable 渠道与 replay 解码
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.
Summary
数字员工现在可以接入 Discord 作为第 5 个消息渠道。在此之前接入渠道仅支持微信、企业微信、飞书、钉钉;本 PR 让用户能在控制台配置 Discord Bot Token,通过 Gateway 长连接接收消息、经 REST API 回复,复用现有渠道无关内核(入站 staging、出站 outbox、身份服务、凭证生命周期)。
实现方式
完全遵循既有渠道接入模式(以钉钉线程模式为模板),无内核结构性改动:
backend/app/channels/adapters/discord.py):normalize/send/start_ingress/stop_ingress协议实现 + 每绑定一线程的DiscordStreamManager(daemon 线程 + 独立 event loop + 5s reconcile),错误分类沿用PermanentError/TransientError分层service_discord_inbox.py+discord_runtime.py):stage-before-ACK 模式,(binding_id, event_id)幂等,绑定围栏校验(channel/active/revision/account-key),envelope 版本化 replaysend()经 Discord RESTPOST /channels/{id}/messages,长文本按 2000 字符分片,idempotency_key稳定派生为nonce(≤25 字符,分片间可复现)GET /users/@me)、discord:bot:{len}:{id}外部账号键、旧 bot 标识符不可变规则、_quiesce_binding_or_409暂停/恢复衔接DiscordSetup.tsx配置界面(含 Message Content Intent 启用提示)关键设计决策
dm:{author};群聊:session_id=channel_id, group_id=guild_idconv_key = group_id or session_id协议channel_id(Discord 无 context_token 体系)target.channel_id验证
npm run build(tsc + vite)通过connected=True,Discord 发消息 → AgentLoop 回复delivered(含群聊与 DM 双场景);另附 3 轮真实 bug 修复(500 / 未接入 / 无回信)均由 Oracle 复核闭环测试清单
test_channel_discord.py(487 行):normalize/send/validate/stage 幂等/fence/stream manager 生命周期/nonce 映射test_discord_api.py:凭证端点(200/400/409/502/凭证不泄漏/不可变标识符)test_channel_outbox.py:discord 投递 target 校验 + daemon→真实 adapter 集成 + 创建者告警跳过风险与说明
content为空,normalize 返回None(UI 有启用提示)service_intake.py:794)在事件卡 processing 时重建的 target 不含channel_id,discord 该窄窗口投递会失败——先于本 PR 已存在,未恶化,建议后续迭代补充