mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 13:44:03 +00:00
fix: use session origin delivery metadata in outbound targets
This commit is contained in:
@@ -236,6 +236,34 @@ describe("resolveSessionDeliveryTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("uses origin provider and accountId when legacy last route fields are absent", () => {
|
||||
const resolved = resolveSessionDeliveryTarget({
|
||||
entry: {
|
||||
sessionId: "sess-origin-route",
|
||||
updatedAt: 1,
|
||||
lastTo: " +1555 ",
|
||||
origin: {
|
||||
provider: " whatsapp ",
|
||||
accountId: " acct-origin ",
|
||||
},
|
||||
},
|
||||
requestedChannel: "last",
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({
|
||||
channel: "whatsapp",
|
||||
to: "+1555",
|
||||
accountId: "acct-origin",
|
||||
threadId: undefined,
|
||||
threadIdExplicit: false,
|
||||
mode: "implicit",
|
||||
lastChannel: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastAccountId: "acct-origin",
|
||||
lastThreadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers explicit targets without reusing lastTo", () => {
|
||||
const resolved = resolveSessionDeliveryTarget({
|
||||
entry: {
|
||||
|
||||
@@ -14,6 +14,11 @@ export type DeliveryContextSessionSource = {
|
||||
lastTo?: string;
|
||||
lastAccountId?: string;
|
||||
lastThreadId?: string | number;
|
||||
origin?: {
|
||||
provider?: string;
|
||||
accountId?: string;
|
||||
threadId?: string | number;
|
||||
};
|
||||
deliveryContext?: DeliveryContext;
|
||||
};
|
||||
|
||||
@@ -165,17 +170,18 @@ export function normalizeSessionDeliveryFields(source?: DeliveryContextSessionSo
|
||||
}
|
||||
|
||||
export function deliveryContextFromSession(
|
||||
entry?: DeliveryContextSessionSource & { origin?: { threadId?: string | number } },
|
||||
entry?: DeliveryContextSessionSource,
|
||||
): DeliveryContext | undefined {
|
||||
if (!entry) {
|
||||
return undefined;
|
||||
}
|
||||
const source: DeliveryContextSessionSource = {
|
||||
channel: entry.channel,
|
||||
channel: entry.channel ?? entry.origin?.provider,
|
||||
lastChannel: entry.lastChannel,
|
||||
lastTo: entry.lastTo,
|
||||
lastAccountId: entry.lastAccountId,
|
||||
lastAccountId: entry.lastAccountId ?? entry.origin?.accountId,
|
||||
lastThreadId: entry.lastThreadId ?? entry.deliveryContext?.threadId ?? entry.origin?.threadId,
|
||||
origin: entry.origin,
|
||||
deliveryContext: entry.deliveryContext,
|
||||
};
|
||||
return normalizeSessionDeliveryFields(source).deliveryContext;
|
||||
|
||||
Reference in New Issue
Block a user