fix: finalize inbound contexts
This commit is contained in:
@@ -378,6 +378,12 @@ describe("monitorIMessageProvider", () => {
|
||||
closeResolve?.();
|
||||
await run;
|
||||
|
||||
expect(replyMock).toHaveBeenCalledOnce();
|
||||
const ctx = replyMock.mock.calls[0]?.[0] as { Body?: string; ChatType?: string };
|
||||
expect(ctx.ChatType).toBe("group");
|
||||
expect(String(ctx.Body ?? "")).toContain("[from:");
|
||||
expect(String(ctx.Body ?? "")).toContain("+15550002222");
|
||||
|
||||
expect(sendMock).toHaveBeenCalledWith(
|
||||
"chat_id:42",
|
||||
"yo",
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
resolveInboundDebounceMs,
|
||||
} from "../../auto-reply/inbound-debounce.js";
|
||||
import { dispatchReplyFromConfig } from "../../auto-reply/reply/dispatch-from-config.js";
|
||||
import { finalizeInboundContext } from "../../auto-reply/reply/inbound-context.js";
|
||||
import {
|
||||
buildPendingHistoryContextFromMap,
|
||||
clearHistoryEntries,
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
} from "../../auto-reply/reply/history.js";
|
||||
import { buildMentionRegexes, matchesMentionPatterns } from "../../auto-reply/reply/mentions.js";
|
||||
import { createReplyDispatcher } from "../../auto-reply/reply/reply-dispatcher.js";
|
||||
import { formatInboundBodyWithSenderMeta } from "../../auto-reply/reply/inbound-sender-meta.js";
|
||||
import { loadConfig } from "../../config/config.js";
|
||||
import {
|
||||
resolveChannelGroupPolicy,
|
||||
@@ -387,12 +389,10 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
}
|
||||
|
||||
const imessageTo = (isGroup ? chatTarget : undefined) || `imessage:${sender}`;
|
||||
const ctxPayload = {
|
||||
const ctxPayload = finalizeInboundContext({
|
||||
Body: combinedBody,
|
||||
BodyForAgent: combinedBody,
|
||||
RawBody: bodyText,
|
||||
CommandBody: bodyText,
|
||||
BodyForCommands: bodyText,
|
||||
From: isGroup ? `group:${chatId}` : `imessage:${sender}`,
|
||||
To: imessageTo,
|
||||
SessionKey: route.sessionKey,
|
||||
@@ -416,7 +416,8 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
// Originating channel for reply routing.
|
||||
OriginatingChannel: "imessage" as const,
|
||||
OriginatingTo: imessageTo,
|
||||
};
|
||||
});
|
||||
ctxPayload.Body = formatInboundBodyWithSenderMeta({ ctx: ctxPayload, body: ctxPayload.Body });
|
||||
|
||||
if (!isGroup) {
|
||||
const sessionCfg = cfg.session;
|
||||
|
||||
Reference in New Issue
Block a user