feat(messages): derive messagePrefix from identity.name
When identity.name is configured, use it for the default messagePrefix instead of hardcoded '[clawdbot]'. Falls back to 'clawdbot' if not set. This allows users to customize how their bot identifies itself in messages by setting identity.name in their config or IDENTITY.md.
This commit is contained in:
committed by
Peter Steinberger
parent
f436808735
commit
8112b276c0
@@ -1959,4 +1959,45 @@ describe("web auto-reply", () => {
|
||||
expect(replies).toEqual(["🦞 🧩 tool1", "🦞 🧩 tool2", "🦞 final"]);
|
||||
resetLoadConfigMock();
|
||||
});
|
||||
|
||||
it("uses identity.name for messagePrefix when set", async () => {
|
||||
setLoadConfigMock(() => ({
|
||||
identity: { name: "Richbot", emoji: "🦁" },
|
||||
}));
|
||||
|
||||
let capturedOnMessage:
|
||||
| ((msg: import("./inbound.js").WebInboundMessage) => Promise<void>)
|
||||
| undefined;
|
||||
const reply = vi.fn();
|
||||
const listenerFactory = async (opts: {
|
||||
onMessage: (
|
||||
msg: import("./inbound.js").WebInboundMessage,
|
||||
) => Promise<void>;
|
||||
}) => {
|
||||
capturedOnMessage = opts.onMessage;
|
||||
return { close: vi.fn() };
|
||||
};
|
||||
|
||||
const resolver = vi.fn().mockResolvedValue({ text: "hello" });
|
||||
|
||||
await monitorWebProvider(false, listenerFactory, false, resolver);
|
||||
expect(capturedOnMessage).toBeDefined();
|
||||
|
||||
await capturedOnMessage?.({
|
||||
body: "hi",
|
||||
from: "+1555",
|
||||
to: "+2666",
|
||||
id: "msg1",
|
||||
sendComposing: vi.fn(),
|
||||
reply,
|
||||
sendMedia: vi.fn(),
|
||||
});
|
||||
|
||||
// Check that resolver received the message with identity-based prefix
|
||||
expect(resolver).toHaveBeenCalled();
|
||||
const resolverArg = resolver.mock.calls[0][0];
|
||||
expect(resolverArg.Body).toContain("[Richbot]");
|
||||
expect(resolverArg.Body).not.toContain("[clawdbot]");
|
||||
resetLoadConfigMock();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user