Slack: route live DM replies to channel

This commit is contained in:
Andrii Furmanets
2026-04-01 16:10:37 +03:00
committed by Peter Steinberger
parent 25da786c68
commit 379f0d78e6
2 changed files with 18 additions and 1 deletions

View File

@@ -379,6 +379,19 @@ describe("slack prepareSlackMessage inbound contract", () => {
expectMainScopedDmClassification(prepared, { includeFromCheck: true });
});
it("uses the concrete DM channel as the live reply target while keeping user-scoped routing", async () => {
const prepared = await prepareMessageWith(
createDmScopeMainSlackCtx(),
createSlackAccount(),
createMainScopedDmMessage({}),
);
expect(prepared).toBeTruthy();
expect(prepared!.replyTarget).toBe("channel:D0ACP6B1T8V");
expect(prepared!.ctxPayload.To).toBe("user:U1");
expect(prepared!.ctxPayload.NativeChannelId).toBe("D0ACP6B1T8V");
});
it("classifies D-prefix DMs when channel_type is missing", async () => {
const message = createMainScopedDmMessage({});
delete message.channel_type;

View File

@@ -800,7 +800,11 @@ export async function prepareSlackMessage(params: {
},
});
const replyTarget = ctxPayload.To ?? undefined;
// Live DM replies should target the concrete Slack DM channel id we just
// received on. This avoids depending on a follow-up conversations.open
// round-trip for the normal reply path while keeping persisted routing
// metadata user-scoped for later session deliveries.
const replyTarget = isDirectMessage ? `channel:${message.channel}` : (ctxPayload.To ?? undefined);
if (!replyTarget) {
return null;
}