mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:48:26 +00:00
refactor: normalize delivery context
Co-authored-by: adam91holt <adam91holt@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,13 @@ export type DeliveryContext = {
|
||||
accountId?: string;
|
||||
};
|
||||
|
||||
type DeliveryContextSessionSource = {
|
||||
channel?: string;
|
||||
lastChannel?: string;
|
||||
lastTo?: string;
|
||||
lastAccountId?: string;
|
||||
};
|
||||
|
||||
export function normalizeDeliveryContext(context?: DeliveryContext): DeliveryContext | undefined {
|
||||
if (!context) return undefined;
|
||||
const channel = typeof context.channel === "string" ? context.channel.trim() : undefined;
|
||||
@@ -19,6 +26,17 @@ export function normalizeDeliveryContext(context?: DeliveryContext): DeliveryCon
|
||||
};
|
||||
}
|
||||
|
||||
export function deliveryContextFromSession(
|
||||
entry?: DeliveryContextSessionSource,
|
||||
): DeliveryContext | undefined {
|
||||
if (!entry) return undefined;
|
||||
return normalizeDeliveryContext({
|
||||
channel: entry.lastChannel ?? entry.channel,
|
||||
to: entry.lastTo,
|
||||
accountId: entry.lastAccountId,
|
||||
});
|
||||
}
|
||||
|
||||
export function mergeDeliveryContext(
|
||||
primary?: DeliveryContext,
|
||||
fallback?: DeliveryContext,
|
||||
|
||||
Reference in New Issue
Block a user