mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:38:25 +00:00
fix: finalize inbound contexts
This commit is contained in:
38
src/auto-reply/reply/inbound-context.test.ts
Normal file
38
src/auto-reply/reply/inbound-context.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { MsgContext } from "../templating.js";
|
||||
import { finalizeInboundContext } from "./inbound-context.js";
|
||||
|
||||
describe("finalizeInboundContext", () => {
|
||||
it("fills BodyForAgent/BodyForCommands and normalizes newlines", () => {
|
||||
const ctx: MsgContext = {
|
||||
Body: "a\\nb\r\nc",
|
||||
RawBody: "raw\\nline",
|
||||
ChatType: "room",
|
||||
From: "group:123@g.us",
|
||||
GroupSubject: "Test",
|
||||
};
|
||||
|
||||
const out = finalizeInboundContext(ctx);
|
||||
expect(out.Body).toBe("a\nb\nc");
|
||||
expect(out.RawBody).toBe("raw\nline");
|
||||
expect(out.BodyForAgent).toBe("a\nb\nc");
|
||||
expect(out.BodyForCommands).toBe("raw\nline");
|
||||
expect(out.ChatType).toBe("channel");
|
||||
expect(out.ConversationLabel).toContain("Test");
|
||||
});
|
||||
|
||||
it("can force BodyForCommands to follow updated CommandBody", () => {
|
||||
const ctx: MsgContext = {
|
||||
Body: "base",
|
||||
BodyForCommands: "<media:audio>",
|
||||
CommandBody: "say hi",
|
||||
From: "signal:+15550001111",
|
||||
ChatType: "direct",
|
||||
};
|
||||
|
||||
finalizeInboundContext(ctx, { forceBodyForCommands: true });
|
||||
expect(ctx.BodyForCommands).toBe("say hi");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user