mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 03:11:10 +00:00
fix: preserve session origin account metadata in announce routing
This commit is contained in:
@@ -38,15 +38,21 @@ export async function resolveAnnounceTarget(params: {
|
||||
match?.deliveryContext && typeof match.deliveryContext === "object"
|
||||
? (match.deliveryContext as Record<string, unknown>)
|
||||
: undefined;
|
||||
const origin =
|
||||
match?.origin && typeof match.origin === "object"
|
||||
? (match.origin as Record<string, unknown>)
|
||||
: undefined;
|
||||
const channel =
|
||||
(typeof deliveryContext?.channel === "string" ? deliveryContext.channel : undefined) ??
|
||||
(typeof match?.lastChannel === "string" ? match.lastChannel : undefined);
|
||||
(typeof match?.lastChannel === "string" ? match.lastChannel : undefined) ??
|
||||
(typeof origin?.provider === "string" ? origin.provider : undefined);
|
||||
const to =
|
||||
(typeof deliveryContext?.to === "string" ? deliveryContext.to : undefined) ??
|
||||
(typeof match?.lastTo === "string" ? match.lastTo : undefined);
|
||||
const accountId =
|
||||
(typeof deliveryContext?.accountId === "string" ? deliveryContext.accountId : undefined) ??
|
||||
(typeof match?.lastAccountId === "string" ? match.lastAccountId : undefined);
|
||||
(typeof match?.lastAccountId === "string" ? match.lastAccountId : undefined) ??
|
||||
(typeof origin?.accountId === "string" ? origin.accountId : undefined);
|
||||
if (channel && to) {
|
||||
return { channel, to, accountId };
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ export type SessionListRow = {
|
||||
channel: string;
|
||||
origin?: {
|
||||
provider?: string;
|
||||
accountId?: string;
|
||||
};
|
||||
spawnedBy?: string;
|
||||
label?: string;
|
||||
|
||||
@@ -201,6 +201,15 @@ export function createSessionsListTool(opts?: {
|
||||
key: displayKey,
|
||||
kind,
|
||||
channel: derivedChannel,
|
||||
origin:
|
||||
originChannel ||
|
||||
(typeof entryOrigin?.accountId === "string" ? entryOrigin.accountId : undefined)
|
||||
? {
|
||||
provider: originChannel,
|
||||
accountId:
|
||||
typeof entryOrigin?.accountId === "string" ? entryOrigin.accountId : undefined,
|
||||
}
|
||||
: undefined,
|
||||
spawnedBy:
|
||||
typeof entry.spawnedBy === "string"
|
||||
? resolveDisplaySessionKey({
|
||||
|
||||
@@ -272,6 +272,31 @@ describe("resolveAnnounceTarget", () => {
|
||||
expect(first).toBeDefined();
|
||||
expect(first?.method).toBe("sessions.list");
|
||||
});
|
||||
|
||||
it("falls back to origin provider and accountId from sessions.list when legacy route fields are absent", async () => {
|
||||
callGatewayMock.mockResolvedValueOnce({
|
||||
sessions: [
|
||||
{
|
||||
key: "agent:main:whatsapp:group:123@g.us",
|
||||
origin: {
|
||||
provider: "whatsapp",
|
||||
accountId: "work",
|
||||
},
|
||||
lastTo: "123@g.us",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const target = await resolveAnnounceTarget({
|
||||
sessionKey: "agent:main:whatsapp:group:123@g.us",
|
||||
displayKey: "agent:main:whatsapp:group:123@g.us",
|
||||
});
|
||||
expect(target).toEqual({
|
||||
channel: "whatsapp",
|
||||
to: "123@g.us",
|
||||
accountId: "work",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("sessions_list gating", () => {
|
||||
|
||||
Reference in New Issue
Block a user