fix: inject reply context into body
This commit is contained in:
@@ -141,7 +141,8 @@ describe("createTelegramBot", () => {
|
||||
|
||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||
const payload = replySpy.mock.calls[0][0];
|
||||
expect(payload.Body).not.toContain("Reply to Ada: Can you summarize this?");
|
||||
expect(payload.Body).toContain("[Replying to Ada]");
|
||||
expect(payload.Body).toContain("Can you summarize this?");
|
||||
expect(payload.ReplyToId).toBe("9001");
|
||||
expect(payload.ReplyToBody).toBe("Can you summarize this?");
|
||||
expect(payload.ReplyToSender).toBe("Ada");
|
||||
|
||||
@@ -124,13 +124,16 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
""
|
||||
).trim();
|
||||
if (!rawBody) return;
|
||||
const replySuffix = replyTarget
|
||||
? `\n\n[Replying to ${replyTarget.sender}]\n${replyTarget.body}\n[/Replying]`
|
||||
: "";
|
||||
const body = formatAgentEnvelope({
|
||||
surface: "Telegram",
|
||||
from: isGroup
|
||||
? buildGroupLabel(msg, chatId)
|
||||
: buildSenderLabel(msg, chatId),
|
||||
timestamp: msg.date ? msg.date * 1000 : undefined,
|
||||
body: rawBody,
|
||||
body: `${rawBody}${replySuffix}`,
|
||||
});
|
||||
|
||||
const ctxPayload = {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user