Fix telegram threadId in deliveryContext
This commit is contained in:
parent
e849df64dc
commit
a642ca4ea8
3 changed files with 31 additions and 3 deletions
|
|
@ -55,7 +55,14 @@ function invalidateSessionStoreCache(storePath: string): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry {
|
function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry {
|
||||||
const normalized = normalizeSessionDeliveryFields(entry);
|
const normalized = normalizeSessionDeliveryFields({
|
||||||
|
channel: entry.channel,
|
||||||
|
lastChannel: entry.lastChannel,
|
||||||
|
lastTo: entry.lastTo,
|
||||||
|
lastAccountId: entry.lastAccountId,
|
||||||
|
lastThreadId: entry.lastThreadId ?? entry.origin?.threadId,
|
||||||
|
deliveryContext: entry.deliveryContext,
|
||||||
|
});
|
||||||
const nextDelivery = normalized.deliveryContext;
|
const nextDelivery = normalized.deliveryContext;
|
||||||
const sameDelivery =
|
const sameDelivery =
|
||||||
(entry.deliveryContext?.channel ?? undefined) === nextDelivery?.channel &&
|
(entry.deliveryContext?.channel ?? undefined) === nextDelivery?.channel &&
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,19 @@ describe("delivery context helpers", () => {
|
||||||
accountId: undefined,
|
accountId: undefined,
|
||||||
threadId: "999",
|
threadId: "999",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
deliveryContextFromSession({
|
||||||
|
channel: "telegram",
|
||||||
|
lastTo: " -1001 ",
|
||||||
|
origin: { threadId: 42 },
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
channel: "telegram",
|
||||||
|
to: "-1001",
|
||||||
|
accountId: undefined,
|
||||||
|
threadId: 42,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("normalizes delivery fields and mirrors them on session entries", () => {
|
it("normalizes delivery fields and mirrors them on session entries", () => {
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,18 @@ export function normalizeSessionDeliveryFields(source?: DeliveryContextSessionSo
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deliveryContextFromSession(
|
export function deliveryContextFromSession(
|
||||||
entry?: DeliveryContextSessionSource,
|
entry?: DeliveryContextSessionSource & { origin?: { threadId?: string | number } },
|
||||||
): DeliveryContext | undefined {
|
): DeliveryContext | undefined {
|
||||||
if (!entry) return undefined;
|
if (!entry) return undefined;
|
||||||
return normalizeSessionDeliveryFields(entry).deliveryContext;
|
const source: DeliveryContextSessionSource = {
|
||||||
|
channel: entry.channel,
|
||||||
|
lastChannel: entry.lastChannel,
|
||||||
|
lastTo: entry.lastTo,
|
||||||
|
lastAccountId: entry.lastAccountId,
|
||||||
|
lastThreadId: entry.lastThreadId ?? entry.origin?.threadId,
|
||||||
|
deliveryContext: entry.deliveryContext,
|
||||||
|
};
|
||||||
|
return normalizeSessionDeliveryFields(source).deliveryContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mergeDeliveryContext(
|
export function mergeDeliveryContext(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue