diff --git a/packages/communication/src/__tests__/discord-provider.test.ts b/packages/communication/src/__tests__/discord-provider.test.ts index 2591f1259..2482e3a6e 100644 --- a/packages/communication/src/__tests__/discord-provider.test.ts +++ b/packages/communication/src/__tests__/discord-provider.test.ts @@ -127,6 +127,51 @@ describe('DiscordCommunicationProvider', () => { expect(posted?.body).toMatchObject({ flags: 4 }); }); + it('omits reply references when posting inside a thread', async () => { + const { server, provider } = createHarness(); + const channelId = '400000000000000001'; + const threadId = '400000000000000002'; + + await provider.postMessage({ + channelId, + threadId, + replyToMessageId: '400000000000000003', + text: 'Thread reply', + }); + + const posted = server.state.requests.find( + (request) => + request.method === 'POST' && + request.path === `/channels/${threadId}/messages`, + ); + expect(posted?.body).not.toHaveProperty('message_reference'); + }); + + it('preserves reply references when posting outside a thread', async () => { + const { server, provider } = createHarness(); + const channelId = '400000000000000001'; + const replyToMessageId = '400000000000000003'; + + await provider.postMessage({ + channelId, + replyToMessageId, + text: 'Channel reply', + }); + + const posted = server.state.requests.find( + (request) => + request.method === 'POST' && + request.path === `/channels/${channelId}/messages`, + ); + expect(posted?.body).toMatchObject({ + message_reference: { + message_id: replyToMessageId, + channel_id: channelId, + fail_if_not_exists: false, + }, + }); + }); + it('reports the text-bearing message when trailing image groups are posted', async () => { const { server, provider } = createHarness({ nonceFactory: vi diff --git a/packages/communication/src/discord-provider.ts b/packages/communication/src/discord-provider.ts index 0792732ae..d767cc521 100644 --- a/packages/communication/src/discord-provider.ts +++ b/packages/communication/src/discord-provider.ts @@ -576,7 +576,7 @@ export class DiscordCommunicationProvider implements CommunicationProviderAdapte ...(index === batchCount - 1 && input.buttons ? { components: buildDiscordComponents(input.buttons) } : {}), - ...(index === 0 && input.replyToMessageId + ...(index === 0 && !input.threadId && input.replyToMessageId ? { message_reference: { message_id: input.replyToMessageId,