Skip to content

feat(panels): 支持指令面板接口 - #3

Open
dragon-fish wants to merge 1 commit into
tencent-connect:mainfrom
dragon-fish:feat/command-panel-api
Open

feat(panels): 支持指令面板接口#3
dragon-fish wants to merge 1 commit into
tencent-connect:mainfrom
dragon-fish:feat/command-panel-api

Conversation

@dragon-fish

Copy link
Copy Markdown

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/panels
bot.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

新增 PanelApisrc/protocol/api/panels.ts),沿用 MessageApi 的形态:由 QQBot 注入自己的凭据,也可从 /protocol 直接消费。

两处设计取舍(对应 issue 里提的问题)

1. 新增 PanelScope 而不是扩展 ChatScope 面板的 scope 取值是 c2c / group / channel / dm,比 ChatScopec2c | group)宽。扩展后者会波及 messagePath()mediaUploadPath() 等一批按二元分支写的函数,而那些接口本来也不支持 channel / dm,所以给面板单独一个类型更干净。

2. 没有提供 syncPanel() 便利方法。 按 CONTRIBUTING 里 "Business abstractions belong in the caller layer" 的原则,「用 remark 认领自己的面板 → 递增 version → 更新」这套编排带有策略色彩,放进了 USAGE.md 的示例而不是 SDK。如果维护者认为它足够通用、值得内置,我可以再加。

验证

pnpm typecheckpnpm lintpnpm 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.3pnpm-lock.yaml 里记录的也是 ^1.0.3),pnpm install 直接报 ERR_PNPM_NO_MATCHING_VERSION。我本地是临时把它改成 ^1.0.3 才跑通验证的,这个改动没有包含在提交里。另开 issue 说明。

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: 支持指令面板接口(/v2/panels),让 slashCommand 能在客户端「/」里露出

1 participant