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();
});
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-"));
testSessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(
@@ -311,7 +312,7 @@ describe("gateway server", () => {
sessionId: "sess-main-webchat",
updatedAt: Date.now(),
lastChannel: "webchat",
lastTo: "ignored",
lastTo: "+1555",
},
},
null,
@@ -351,8 +352,9 @@ describe("gateway server", () => {
const spy = vi.mocked(agentCommand);
expect(spy).toHaveBeenCalled();
const call = spy.mock.calls.at(-1)?.[0] as Record<string, unknown>;
expect(call.provider).toBe("webchat");
expect(call.deliver).toBe(false);
expect(call.provider).toBe("whatsapp");
expect(call.to).toBe("+1555");
expect(call.deliver).toBe(true);
expect(call.bestEffortDeliver).toBe(true);
expect(call.sessionId).toBe("sess-main-webchat");

View File

@@ -1174,7 +1174,11 @@ export async function startGatewayServer(
const resolvedChannel = (() => {
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 (
requestedChannel === "whatsapp" ||
@@ -1183,7 +1187,9 @@ export async function startGatewayServer(
) {
return requestedChannel;
}
return lastChannel ?? "whatsapp";
return lastChannel && lastChannel !== "webchat"
? lastChannel
: "whatsapp";
})();
const resolvedTo = (() => {