Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugin-src/host/delivery-service.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ export class DeliveryService {
throw deliveryError('capability-unavailable');
}
if (account.account?.fingerprint !== expectedFingerprint) throw deliveryError('account-changed');
const receiptConversation = adapter.channel === 'feishu' && target.kind === 'group'
const receiptConversation = adapter.channel === 'feishu'
&& (target.kind === 'group' || typeof target.route.chatId === 'string')
? target.route.chatId : adapter.channel === 'slack' && target.kind === 'conversation'
? target.route.channelId : adapter.channel === 'qq' && target.kind === 'group'
? target.route.groupOpenId : adapter.channel === 'weixin' && target.kind === 'user'
Expand Down
8 changes: 6 additions & 2 deletions src/channels/feishu/feishu-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,11 @@ export class FeishuRuntime {
error.code = 'bad-request';
throw error;
}
if (typeof receipt !== 'boolean' || (receipt && target.kind !== 'group'))
// A receipt proves the exact conversation: a group chat, or the private
// chat a saved user target names alongside its open_id.
const receiptConversation = target.kind === 'group' ? receiveId
: nonEmptyString(target?.route?.chatId);
if (typeof receipt !== 'boolean' || (receipt && !receiptConversation))
throw Object.assign(new Error('capability-unavailable'), { code: 'capability-unavailable' });
signal?.throwIfAborted();
// Use the same native Markdown element as chat, without opening a stream
Expand Down Expand Up @@ -846,7 +850,7 @@ export class FeishuRuntime {
if (!receipt) return { sent: true };
const messageId = response?.data?.message_id;
const conversationId = response?.data?.chat_id;
if (typeof messageId !== 'string' || !messageId || messageId.length > 512 || conversationId !== receiveId)
if (typeof messageId !== 'string' || !messageId || messageId.length > 512 || conversationId !== receiptConversation)
throw Object.assign(new Error('send-result-unknown'), { code: 'send-result-unknown' });
return { sent: true, receipt: { version: 1, messageId, conversationId } };
}
Expand Down
16 changes: 16 additions & 0 deletions test/channels/feishu/proactive-markdown.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,19 @@ test('opt-in group receipt survives runtime and adapter without changing legacy
await assert.rejects(fx.runtime.sendProactiveText(targets[0], text, { receipt: true }), { code: 'capability-unavailable' });
assert.equal(fx.sends.length, before);
});

test('a saved private-chat target returns a checked receipt for its exact chat (#3842)', async t => {
const fx = await fixture(t);
const privateChat = { targetId: 'owner-dm', kind: 'user', route: { openId: 'ou_fixture_owner', chatId: 'oc_fixtureowner' } };
targets.push(privateChat);
t.after(() => targets.splice(targets.indexOf(privateChat), 1));
fx.respondWith(() => ({ code: 0, data: { message_id: 'om_dm_receipt', chat_id: 'oc_fixtureowner' } }));
assert.deepEqual(await fx.runtime.sendProactiveText(privateChat, text, { receipt: true }), {
sent: true, receipt: { version: 1, messageId: 'om_dm_receipt', conversationId: 'oc_fixtureowner' },
});
const sent = fx.sends.at(-1);
assert.equal(sent.params.receive_id_type, 'open_id');
assert.equal(sent.data.receive_id, 'ou_fixture_owner');
fx.respondWith(() => ({ code: 0, data: { message_id: 'om_dm_receipt', chat_id: 'oc_other' } }));
await assert.rejects(fx.runtime.sendProactiveText(privateChat, text, { receipt: true }), { code: 'send-result-unknown' });
});
26 changes: 26 additions & 0 deletions test/delivery-service.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,32 @@ test('Weixin checked post requires a current final fence and keeps client acknow
assert.equal(sends, 1);
});

test('Feishu checked post receipts a saved private chat by its chat id, never an open_id-only user (#3842)', async () => {
const fx = checkedFixture();
fx.adapter.describeAccount = async () => ({version: 1, capabilities: ['proactive-text-checked', 'proactive-receipt-checked', 'proactive-fence-checked'], account: {fingerprint: fx.fingerprint}});
fx.service.registerAdapter(fx.adapter);
const {createHash} = await import('node:crypto');
const digest = (target) => createHash('sha256').update(JSON.stringify({kind: target.kind,
route: Object.fromEntries(Object.entries(target.route).sort(([a], [b]) => a < b ? -1 : 1))})).digest('hex');
const privateChat = {targetId: 'owner-dm', kind: 'user', route: {openId: 'ou_owner', chatId: 'oc_ownerdm'}};
const openIdOnly = {targetId: 'owner-open-id', kind: 'user', route: {openId: 'ou_owner'}};
await fx.service.createTarget('bot_one', privateChat);
await fx.service.createTarget('bot_one', openIdOnly);
let sends = 0;
fx.adapter.sendText = async (_id, saved, _text, opts) => {
assert.equal(opts.receipt, true);
if (!opts.beforeSend()) throw Object.assign(new Error('cancelled'), {code: 'cancelled'});
sends++;
return {sent: true, receipt: {version: 1, messageId: 'om_dm', conversationId: saved.route.chatId}};
};
const options = {expectedFingerprint: fx.fingerprint, receipt: true, beforeSend: () => true};
assert.deepEqual(await fx.service.sendChecked('bot_one', 'owner-dm', 'Report', {...options, expectedTargetDigest: digest(privateChat)}),
{sent: true, receipt: {version: 1, messageId: 'om_dm', conversationId: 'oc_ownerdm'}});
await assert.rejects(fx.service.sendChecked('bot_one', 'owner-open-id', 'Report', {...options, expectedTargetDigest: digest(openIdOnly)}),
{code: 'capability-unavailable'});
assert.equal(sends, 1);
});

async function checkedTarget(fx) {
const target = {targetId: 'self', kind: 'user', route: {openId: 'ou_self'}};
await fx.service.createTarget('bot_one', target);
Expand Down