feat(panels): 支持指令面板接口 - #3
Open
dragon-fish wants to merge 1 commit into
Open
Conversation
The command panel is the list a client shows when the user taps the "/" affordance in the input box. `slashCommand` matches those commands once they arrive, but nothing in the SDK could publish the panel in the first place, so the affordance stayed empty unless the caller hand-rolled the endpoints through `bot.api`. Cover the documented endpoints: list (paged), get, create, update, delete, and the target association used by `specific` panels. `PanelApi` follows the existing protocol-layer shape, and `QQBot` forwards its own credentials. Panel scope is wider than `ChatScope` — it also covers `channel` and `dm` — so it gets its own `PanelScope` type rather than widening the one that `messagePath()` and friends branch on. No sync helper: claiming a panel by `remark` and bumping `version` is a policy the caller owns, so it lives in USAGE.md as an example instead. Refs tencent-connect#2
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.
Closes #2
背景
slashCommand中间件能识别用户发来的指令,但用户点击输入框「/」时弹出的面板需要调用/v2/panels注册,SDK 此前没有封装这组接口——想让指令可见只能用bot.api.post()自己拼端点。改动
按官方文档覆盖了这组接口:
bot.listPanels(query)GET /v2/panels(分页)bot.getPanel(id)GET /v2/panels/{panel_id}bot.createPanel(req)POST /v2/panelsbot.updatePanel(id, panel)PUT /v2/panels/{panel_id}bot.deletePanel(id)DELETE /v2/panels/{panel_id}bot.updatePanelTarget(id, req)PUT /v2/panels/{panel_id}/target新增
PanelApi(src/protocol/api/panels.ts),沿用MessageApi的形态:由QQBot注入自己的凭据,也可从/protocol直接消费。两处设计取舍(对应 issue 里提的问题)
1. 新增
PanelScope而不是扩展ChatScope。 面板的scope取值是c2c/group/channel/dm,比ChatScope(c2c|group)宽。扩展后者会波及messagePath()、mediaUploadPath()等一批按二元分支写的函数,而那些接口本来也不支持 channel / dm,所以给面板单独一个类型更干净。2. 没有提供
syncPanel()便利方法。 按 CONTRIBUTING 里 "Business abstractions belong in the caller layer" 的原则,「用remark认领自己的面板 → 递增version→ 更新」这套编排带有策略色彩,放进了USAGE.md的示例而不是 SDK。如果维护者认为它足够通用、值得内置,我可以再加。验证
pnpm typecheck、pnpm lint、pnpm test均通过(176 个用例,其中新增 11 个覆盖路径拼接、query 参数、请求体形状和 facade 的凭据传递)。文档已更新:
USAGE.md新增「13. 指令面板」一节(含分页、specific面板关联对象、平台限制表),后续章节顺延重编号;README.md/README.zh-CN.md各加一段。附带发现(未包含在本 PR 中)
当前
main在公网上装不上依赖:package.json声明mpg123-decoder: ^1.0.4,但 npm 上最新版本是1.0.3(pnpm-lock.yaml里记录的也是^1.0.3),pnpm install直接报ERR_PNPM_NO_MATCHING_VERSION。我本地是临时把它改成^1.0.3才跑通验证的,这个改动没有包含在提交里。另开 issue 说明。