feat: persist session origin metadata across connectors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export * from "./sessions/group.js";
|
||||
export * from "./sessions/metadata.js";
|
||||
export * from "./sessions/main-session.js";
|
||||
export * from "./sessions/paths.js";
|
||||
export * from "./sessions/session-key.js";
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
normalizeSessionDeliveryFields,
|
||||
type DeliveryContext,
|
||||
} from "../../utils/delivery-context.js";
|
||||
import type { MsgContext } from "../../auto-reply/templating.js";
|
||||
import { deriveSessionMetaPatch } from "./metadata.js";
|
||||
import { mergeSessionEntry, type SessionEntry } from "./types.js";
|
||||
|
||||
// ============================================================================
|
||||
@@ -334,6 +336,31 @@ export async function updateSessionStoreEntry(params: {
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordSessionMetaFromInbound(params: {
|
||||
storePath: string;
|
||||
sessionKey: string;
|
||||
ctx: MsgContext;
|
||||
groupResolution?: import("./types.js").GroupKeyResolution | null;
|
||||
createIfMissing?: boolean;
|
||||
}): Promise<SessionEntry | null> {
|
||||
const { storePath, sessionKey, ctx } = params;
|
||||
const createIfMissing = params.createIfMissing ?? true;
|
||||
return await updateSessionStore(storePath, (store) => {
|
||||
const existing = store[sessionKey];
|
||||
const patch = deriveSessionMetaPatch({
|
||||
ctx,
|
||||
sessionKey,
|
||||
existing,
|
||||
groupResolution: params.groupResolution,
|
||||
});
|
||||
if (!patch) return existing ?? null;
|
||||
if (!existing && !createIfMissing) return null;
|
||||
const next = mergeSessionEntry(existing, patch);
|
||||
store[sessionKey] = next;
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateLastRoute(params: {
|
||||
storePath: string;
|
||||
sessionKey: string;
|
||||
|
||||
@@ -11,6 +11,17 @@ export type SessionChannelId = ChannelId | "webchat";
|
||||
|
||||
export type SessionChatType = NormalizedChatType;
|
||||
|
||||
export type SessionOrigin = {
|
||||
label?: string;
|
||||
provider?: string;
|
||||
surface?: string;
|
||||
chatType?: SessionChatType;
|
||||
from?: string;
|
||||
to?: string;
|
||||
accountId?: string;
|
||||
threadId?: string | number;
|
||||
};
|
||||
|
||||
export type SessionEntry = {
|
||||
/**
|
||||
* Last delivered heartbeat payload (used to suppress duplicate heartbeat notifications).
|
||||
@@ -69,6 +80,7 @@ export type SessionEntry = {
|
||||
subject?: string;
|
||||
groupChannel?: string;
|
||||
space?: string;
|
||||
origin?: SessionOrigin;
|
||||
deliveryContext?: DeliveryContext;
|
||||
lastChannel?: SessionChannelId;
|
||||
lastTo?: string;
|
||||
|
||||
Reference in New Issue
Block a user