fix: inject reply context into body

This commit is contained in:
Peter Steinberger
2025-12-23 02:44:38 +01:00
parent 950432eac0
commit 67a3dda53a
7 changed files with 23 additions and 6 deletions

View File

@@ -1786,10 +1786,13 @@ describe("web auto-reply", () => {
ReplyToId?: string;
ReplyToBody?: string;
ReplyToSender?: string;
Body?: string;
};
expect(callArg.ReplyToId).toBe("q1");
expect(callArg.ReplyToBody).toBe("original");
expect(callArg.ReplyToSender).toBe("+1999");
expect(callArg.Body).toContain("[Replying to +1999]");
expect(callArg.Body).toContain("original");
});
it("applies responsePrefix to regular replies", async () => {

View File

@@ -933,6 +933,12 @@ export async function monitorWebProvider(
const backgroundTasks = new Set<Promise<unknown>>();
const formatReplyContext = (msg: WebInboundMsg) => {
if (!msg.replyToBody) return null;
const sender = msg.replyToSender ?? "unknown sender";
return `[Replying to ${sender}]\n${msg.replyToBody}\n[/Replying]`;
};
const buildLine = (msg: WebInboundMsg) => {
// Build message prefix: explicit config > default based on allowFrom
let messagePrefix = cfg.inbound?.messagePrefix;
@@ -945,7 +951,10 @@ export async function monitorWebProvider(
msg.chatType === "group"
? `${msg.senderName ?? msg.senderE164 ?? "Someone"}: `
: "";
const baseLine = `${prefixStr}${senderLabel}${msg.body}`;
const replyContext = formatReplyContext(msg);
const baseLine = `${prefixStr}${senderLabel}${msg.body}${
replyContext ? `\n\n${replyContext}` : ""
}`;
// Wrap with standardized envelope for the agent.
return formatAgentEnvelope({