mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 00:23:29 +00:00
refactor: reuse broadcast route key construction
This commit is contained in:
@@ -11,6 +11,39 @@ import { whatsappInboundLog } from "../loggers.js";
|
|||||||
import type { WebInboundMsg } from "../types.js";
|
import type { WebInboundMsg } from "../types.js";
|
||||||
import type { GroupHistoryEntry } from "./process-message.js";
|
import type { GroupHistoryEntry } from "./process-message.js";
|
||||||
|
|
||||||
|
function buildBroadcastRouteKeys(params: {
|
||||||
|
cfg: ReturnType<typeof loadConfig>;
|
||||||
|
msg: WebInboundMsg;
|
||||||
|
route: ReturnType<typeof resolveAgentRoute>;
|
||||||
|
peerId: string;
|
||||||
|
agentId: string;
|
||||||
|
}) {
|
||||||
|
const sessionKey = buildAgentSessionKey({
|
||||||
|
agentId: params.agentId,
|
||||||
|
channel: "whatsapp",
|
||||||
|
accountId: params.route.accountId,
|
||||||
|
peer: {
|
||||||
|
kind: params.msg.chatType === "group" ? "group" : "direct",
|
||||||
|
id: params.peerId,
|
||||||
|
},
|
||||||
|
dmScope: params.cfg.session?.dmScope,
|
||||||
|
identityLinks: params.cfg.session?.identityLinks,
|
||||||
|
});
|
||||||
|
const mainSessionKey = buildAgentMainSessionKey({
|
||||||
|
agentId: params.agentId,
|
||||||
|
mainKey: DEFAULT_MAIN_KEY,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
sessionKey,
|
||||||
|
mainSessionKey,
|
||||||
|
lastRoutePolicy: deriveLastRoutePolicy({
|
||||||
|
sessionKey,
|
||||||
|
mainSessionKey,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function maybeBroadcastMessage(params: {
|
export async function maybeBroadcastMessage(params: {
|
||||||
cfg: ReturnType<typeof loadConfig>;
|
cfg: ReturnType<typeof loadConfig>;
|
||||||
msg: WebInboundMsg;
|
msg: WebInboundMsg;
|
||||||
@@ -52,41 +85,17 @@ export async function maybeBroadcastMessage(params: {
|
|||||||
whatsappInboundLog.warn(`Broadcast agent ${agentId} not found in agents.list; skipping`);
|
whatsappInboundLog.warn(`Broadcast agent ${agentId} not found in agents.list; skipping`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const routeKeys = buildBroadcastRouteKeys({
|
||||||
|
cfg: params.cfg,
|
||||||
|
msg: params.msg,
|
||||||
|
route: params.route,
|
||||||
|
peerId: params.peerId,
|
||||||
|
agentId: normalizedAgentId,
|
||||||
|
});
|
||||||
const agentRoute = {
|
const agentRoute = {
|
||||||
...params.route,
|
...params.route,
|
||||||
agentId: normalizedAgentId,
|
agentId: normalizedAgentId,
|
||||||
sessionKey: buildAgentSessionKey({
|
...routeKeys,
|
||||||
agentId: normalizedAgentId,
|
|
||||||
channel: "whatsapp",
|
|
||||||
accountId: params.route.accountId,
|
|
||||||
peer: {
|
|
||||||
kind: params.msg.chatType === "group" ? "group" : "direct",
|
|
||||||
id: params.peerId,
|
|
||||||
},
|
|
||||||
dmScope: params.cfg.session?.dmScope,
|
|
||||||
identityLinks: params.cfg.session?.identityLinks,
|
|
||||||
}),
|
|
||||||
mainSessionKey: buildAgentMainSessionKey({
|
|
||||||
agentId: normalizedAgentId,
|
|
||||||
mainKey: DEFAULT_MAIN_KEY,
|
|
||||||
}),
|
|
||||||
lastRoutePolicy: deriveLastRoutePolicy({
|
|
||||||
sessionKey: buildAgentSessionKey({
|
|
||||||
agentId: normalizedAgentId,
|
|
||||||
channel: "whatsapp",
|
|
||||||
accountId: params.route.accountId,
|
|
||||||
peer: {
|
|
||||||
kind: params.msg.chatType === "group" ? "group" : "direct",
|
|
||||||
id: params.peerId,
|
|
||||||
},
|
|
||||||
dmScope: params.cfg.session?.dmScope,
|
|
||||||
identityLinks: params.cfg.session?.identityLinks,
|
|
||||||
}),
|
|
||||||
mainSessionKey: buildAgentMainSessionKey({
|
|
||||||
agentId: normalizedAgentId,
|
|
||||||
mainKey: DEFAULT_MAIN_KEY,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user