fix(gateway): treat webchat last as whatsapp

This commit is contained in:
Peter Steinberger
2025-12-12 21:05:26 +00:00
parent e3b50b7d12
commit 211efffa10
2 changed files with 14 additions and 6 deletions

View File

@@ -300,7 +300,8 @@ describe("gateway server", () => {
await server.close(); await server.close();
}); });
test("agent forces no-deliver when last-channel is webchat", async () => { test("agent ignores webchat last-channel for routing", async () => {
testAllowFrom = ["+1555"];
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-")); const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-"));
testSessionStorePath = path.join(dir, "sessions.json"); testSessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile( await fs.writeFile(
@@ -311,7 +312,7 @@ describe("gateway server", () => {
sessionId: "sess-main-webchat", sessionId: "sess-main-webchat",
updatedAt: Date.now(), updatedAt: Date.now(),
lastChannel: "webchat", lastChannel: "webchat",
lastTo: "ignored", lastTo: "+1555",
}, },
}, },
null, null,
@@ -351,8 +352,9 @@ describe("gateway server", () => {
const spy = vi.mocked(agentCommand); const spy = vi.mocked(agentCommand);
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
const call = spy.mock.calls.at(-1)?.[0] as Record<string, unknown>; const call = spy.mock.calls.at(-1)?.[0] as Record<string, unknown>;
expect(call.provider).toBe("webchat"); expect(call.provider).toBe("whatsapp");
expect(call.deliver).toBe(false); expect(call.to).toBe("+1555");
expect(call.deliver).toBe(true);
expect(call.bestEffortDeliver).toBe(true); expect(call.bestEffortDeliver).toBe(true);
expect(call.sessionId).toBe("sess-main-webchat"); expect(call.sessionId).toBe("sess-main-webchat");

View File

@@ -1174,7 +1174,11 @@ export async function startGatewayServer(
const resolvedChannel = (() => { const resolvedChannel = (() => {
if (requestedChannel === "last") { if (requestedChannel === "last") {
return lastChannel ?? "whatsapp"; // WebChat is not a deliverable surface. Treat it as "unset" for routing,
// so VoiceWake and CLI callers don't get stuck with deliver=false.
return lastChannel && lastChannel !== "webchat"
? lastChannel
: "whatsapp";
} }
if ( if (
requestedChannel === "whatsapp" || requestedChannel === "whatsapp" ||
@@ -1183,7 +1187,9 @@ export async function startGatewayServer(
) { ) {
return requestedChannel; return requestedChannel;
} }
return lastChannel ?? "whatsapp"; return lastChannel && lastChannel !== "webchat"
? lastChannel
: "whatsapp";
})(); })();
const resolvedTo = (() => { const resolvedTo = (() => {