Feat: 发送图文ark卡片 (#355)

* feat(onebot): implement send tuwen ark

* test: add unit tests for send_ark action

* test(onebot): update canonical action docs count expectation to 191

* refactor(protocol,onebot): update 0xdc2_34 ark implementation and test coverage

- Rename action send_ark -> send_tuwen_ark to distinguish from structmsg and contact-share arks.
- Clarify SSO command mapping (OidbSvcTrpcTcp.0xdc2_34) and default param behavior in comments/docs.
- Adjust peerType, field3, and previewUrl to pb_optional to preserve 0/empty values during proton encoding.
- Update OneBot handler, tests, and auto-generated MCP tool catalog specs.

* style(protocol): fix indentation in rich-body-decoder tests
This commit is contained in:
H3CoF6 authored and GitHub committed 2026-08-20 12:12:39 +08:00
1 parent 62256ee816
commit 8fbddf67bf
11 files changed
+734 -137

No files matched your search

+49
View File
@@ -1739,6 +1739,55 @@ export const actions = [
},
}),
// send_tuwen_ark — send a custom 图文 (URL-share) ark card to a C2C peer or group (0xdc2_34).
// targetId at AppInfo[11] and Meta[2]; Meta.peerType: 0=C2C, 1=group.
// 与 send_ark_share 的区别:send_ark_share 只获取推荐联系人 JSON 不发送;
// 与 send_msg share/json 的区别:后者发送 structmsg 图文卡且有 message_id,
// 本 action 发送固定图文 ark 模板,返回 null(无法用于撤回/设精华)。
defineAction({
name: 'send_tuwen_ark',
summary: '发送图文 Ark 卡片(私聊/群聊)',
readOnly: false,
returns: 'null',
returnsSchema: { type: 'null' },
params: {
user_id: f.userId().optional(),
group_id: f.groupId().optional(),
title: f.string(),
desc: f.string(),
summary: f.string().default('[分享]'),
preview_url: f.string().default('https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png'),
jump_url: f.string(),
},
run: async (p, ctx) => {
if (p.group_id) {
await ctx.bridge.apis.contacts.sendTuwenArk({
targetId: p.group_id,
peerType: 1,
title: p.title,
desc: p.desc,
summary: p.summary,
previewUrl: p.preview_url,
jumpUrl: p.jump_url,
});
return okResponse(null);
}
if (p.user_id) {
await ctx.bridge.apis.contacts.sendTuwenArk({
targetId: p.user_id,
peerType: 0,
title: p.title,
desc: p.desc,
summary: p.summary,
previewUrl: p.preview_url,
jumpUrl: p.jump_url,
});
return okResponse(null);
}
return failedResponse(RETCODE.BAD_REQUEST, 'user_id or group_id is required');
},
}),
// share_group_ex / send_group_ark_share — group-only Ark share. NapCat uses
// a distinct kernel API (getArkJsonGroupShare) we did NOT RE; we route to
// the fully-RE'd group recommend-contact ark (0x8b7_5), the closest
@@ -2065,6 +2065,84 @@ describe('extended-actions / TierB ③ share + doubt + robot-option', () => {
});
});
// ─── TierB ③: send_ark (图文 Ark 卡片, OIDB 0xdc2_34) ───
describe('extended-actions / send_tuwen_ark', () => {
const arkParams = {
title: '标题',
desc: '描述',
jump_url: 'https://example.com',
};
it('routes to group when group_id is given (peerType=1)', async () => {
const sendTuwenArk = vi.fn(async () => {});
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
group_id: 12345,
...arkParams,
});
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: null });
expect(sendTuwenArk).toHaveBeenCalledWith({
targetId: 12345,
peerType: 1,
title: '标题',
desc: '描述',
summary: '[分享]',
previewUrl: 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png',
jumpUrl: 'https://example.com',
});
});
it('routes to C2C when user_id is given (peerType=0)', async () => {
const sendTuwenArk = vi.fn(async () => {});
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
user_id: 10001,
...arkParams,
});
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: null });
expect(sendTuwenArk).toHaveBeenCalledWith({
targetId: 10001,
peerType: 0,
title: '标题',
desc: '描述',
summary: '[分享]',
previewUrl: 'https://tangram-1251316161.file.myqcloud.com/files/20210721/e50a8e37e08f29bf1ffc7466e1950690.png',
jumpUrl: 'https://example.com',
});
});
it('prefers group_id over user_id when both are supplied', async () => {
const sendTuwenArk = vi.fn(async () => {});
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
group_id: 12345,
user_id: 10001,
...arkParams,
});
expect(res).toMatchObject({ status: 'ok' });
expect(sendTuwenArk).toHaveBeenCalledWith(expect.objectContaining({ peerType: 1, targetId: 12345 }));
});
it('rejects when neither user_id nor group_id is given', async () => {
const sendTuwenArk = vi.fn();
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', { ...arkParams });
expect(res).toMatchObject({ status: 'failed', retcode: 1400 });
expect(sendTuwenArk).not.toHaveBeenCalled();
});
it('surfaces bridge errors as action_failed', async () => {
const sendTuwenArk = vi.fn(async () => { throw new Error('oidb 0xdc2 rejected'); });
const bridge = fakeBridge({ apis: { contacts: { sendTuwenArk } } });
const res = await makeHandler(fakeCtx(bridge)).handle('send_tuwen_ark', {
group_id: 12345,
...arkParams,
});
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'oidb 0xdc2 rejected' });
});
});
// ─── napcat-parity: get_qun_album_list (QQ NT AlbumService) ───
describe('extended-actions / get_group_album_list', () => {
it('returns the cover and last-upload metadata from the core facade', async () => {
@@ -27,7 +27,7 @@ function createControlPort(): {
messages: MessageStoreMigrationWorkerMessage[];
send(message: unknown): void;
listenerCount(): number;
} {
} {
const messages: MessageStoreMigrationWorkerMessage[] = [];
const events = new EventEmitter();
return {