Skip to content

Commit 06957a6

Browse files
authored
fix(discord): keep acknowledged interaction replies private (#118611)
1 parent db7c484 commit 06957a6

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎extensions/discord/src/monitor/agent-components.plugin-interactive.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ export async function dispatchPluginDiscordInteractiveEvent(params: {
6666
},
6767
reply: async ({ text, ephemeral = true }: { text: string; ephemeral?: boolean }) => {
6868
responded = true;
69-
await params.interaction.reply({
70-
content: text,
71-
ephemeral,
72-
});
69+
const payload = { content: text, ephemeral };
70+
// Deferred component replies edit the public source; follow-ups preserve reply visibility.
71+
await (acknowledged
72+
? params.interaction.followUp(payload)
73+
: params.interaction.reply(payload));
7374
},
7475
followUp: async ({ text, ephemeral = true }: { text: string; ephemeral?: boolean }) => {
7576
responded = true;

‎extensions/discord/src/monitor/monitor.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,48 @@ describe("discord component interactions", () => {
919919
expect(dispatchReplyMock).not.toHaveBeenCalled();
920920
});
921921

922+
it.each([
923+
{ visibility: "private", ephemeral: true },
924+
{ visibility: "public", ephemeral: false },
925+
{ visibility: "default-private", ephemeral: undefined },
926+
])(
927+
"sends $visibility plugin replies as new messages after component acknowledgment",
928+
async ({ ephemeral }) => {
929+
registerDiscordComponentEntries({
930+
entries: [createButtonEntry({ callbackData: "codex:approve" })],
931+
modals: [],
932+
});
933+
dispatchPluginInteractiveHandlerMock.mockImplementation(async (params: unknown) => {
934+
const typedParams = params as {
935+
onMatched: () => Promise<void>;
936+
respond: { reply: (payload: { text: string; ephemeral?: boolean }) => Promise<void> };
937+
};
938+
await typedParams.onMatched();
939+
await typedParams.respond.reply({
940+
text: "Plugin result",
941+
...(ephemeral === undefined ? {} : { ephemeral }),
942+
});
943+
return { matched: true, handled: true, duplicate: false };
944+
});
945+
946+
const acknowledge = vi.fn().mockResolvedValue(undefined);
947+
const followUp = vi.fn().mockResolvedValue(undefined);
948+
const reply = vi.fn().mockResolvedValue(undefined);
949+
const button = createDiscordComponentButton(createComponentContext());
950+
const { interaction } = createComponentButtonInteraction({ acknowledge, followUp, reply });
951+
952+
await button.run(interaction, { cid: "btn_1" } as ComponentData);
953+
954+
expect(acknowledge).toHaveBeenCalledTimes(1);
955+
expect(followUp).toHaveBeenCalledWith({
956+
content: "Plugin result",
957+
ephemeral: ephemeral ?? true,
958+
});
959+
expect(reply).not.toHaveBeenCalled();
960+
expect(dispatchReplyMock).not.toHaveBeenCalled();
961+
},
962+
);
963+
922964
it("lets plugin Discord interactions clear components after acknowledging", async () => {
923965
registerDiscordComponentEntries({
924966
entries: [createButtonEntry({ callbackData: "codex:approve" })],

0 commit comments

Comments
 (0)