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

@@ -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 {