fix(signal): canonicalize message targets in tool and inbound flows

This commit is contained in:
Josh Avant
2026-02-17 14:17:22 -08:00
committed by GitHub
parent 9a2c39419e
commit b20339a232
6 changed files with 135 additions and 30 deletions

View File

@@ -51,4 +51,41 @@ describe("signal createSignalEventHandler inbound contract", () => {
expect(String(contextWithBody.Body ?? "")).toMatch(/Alice.*:/);
expect(String(contextWithBody.Body ?? "")).not.toContain("[from:");
});
it("normalizes direct chat To/OriginatingTo targets to canonical Signal ids", async () => {
capturedCtx = undefined;
const handler = createSignalEventHandler(
createBaseSignalEventHandlerDeps({
// oxlint-disable-next-line typescript/no-explicit-any
cfg: { messages: { inbound: { debounceMs: 0 } } } as any,
historyLimit: 0,
}),
);
await handler({
event: "receive",
data: JSON.stringify({
envelope: {
sourceNumber: "+15550002222",
sourceName: "Bob",
timestamp: 1700000000001,
dataMessage: {
message: "hello",
attachments: [],
},
},
}),
});
expect(capturedCtx).toBeTruthy();
const context = capturedCtx as unknown as {
ChatType?: string;
To?: string;
OriginatingTo?: string;
};
expect(context.ChatType).toBe("direct");
expect(context.To).toBe("+15550002222");
expect(context.OriginatingTo).toBe("+15550002222");
});
});

View File

@@ -21,6 +21,7 @@ import { createReplyDispatcherWithTyping } from "../../auto-reply/reply/reply-di
import { resolveControlCommandGate } from "../../channels/command-gating.js";
import { logInboundDrop, logTypingFailure } from "../../channels/logging.js";
import { resolveMentionGatingWithBypass } from "../../channels/mention-gating.js";
import { normalizeSignalMessagingTarget } from "../../channels/plugins/normalize/signal.js";
import { createReplyPrefixOptions } from "../../channels/reply-prefix.js";
import { recordInboundSession } from "../../channels/session.js";
import { createTypingCallbacks } from "../../channels/typing.js";
@@ -126,7 +127,10 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {
}),
});
}
const signalTo = entry.isGroup ? `group:${entry.groupId}` : `signal:${entry.senderRecipient}`;
const signalToRaw = entry.isGroup
? `group:${entry.groupId}`
: `signal:${entry.senderRecipient}`;
const signalTo = normalizeSignalMessagingTarget(signalToRaw) ?? signalToRaw;
const inboundHistory =
entry.isGroup && historyKey && deps.historyLimit > 0
? (deps.groupHistories.get(historyKey) ?? []).map((historyEntry) => ({