mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
refactor(routing): centralize inbound last-route policy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { loadConfig } from "../../../config/config.js";
|
||||
import type { resolveAgentRoute } from "../../../routing/resolve-route.js";
|
||||
import { buildAgentSessionKey } from "../../../routing/resolve-route.js";
|
||||
import { buildAgentSessionKey, deriveLastRoutePolicy } from "../../../routing/resolve-route.js";
|
||||
import {
|
||||
buildAgentMainSessionKey,
|
||||
DEFAULT_MAIN_KEY,
|
||||
@@ -70,6 +70,23 @@ export async function maybeBroadcastMessage(params: {
|
||||
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 {
|
||||
|
||||
@@ -19,7 +19,10 @@ import { recordSessionMetaFromInbound } from "../../../config/sessions.js";
|
||||
import { logVerbose, shouldLogVerbose } from "../../../globals.js";
|
||||
import type { getChildLogger } from "../../../logging.js";
|
||||
import { getAgentScopedMediaLocalRoots } from "../../../media/local-roots.js";
|
||||
import type { resolveAgentRoute } from "../../../routing/resolve-route.js";
|
||||
import {
|
||||
resolveInboundLastRouteSessionKey,
|
||||
type resolveAgentRoute,
|
||||
} from "../../../routing/resolve-route.js";
|
||||
import {
|
||||
readStoreAllowFromForDmPolicy,
|
||||
resolvePinnedMainDmOwnerFromAllowlist,
|
||||
@@ -339,9 +342,13 @@ export async function processMessage(params: {
|
||||
});
|
||||
const shouldUpdateMainLastRoute =
|
||||
!pinnedMainDmRecipient || pinnedMainDmRecipient === dmRouteTarget;
|
||||
const inboundLastRouteSessionKey = resolveInboundLastRouteSessionKey({
|
||||
route: params.route,
|
||||
sessionKey: params.route.sessionKey,
|
||||
});
|
||||
if (
|
||||
dmRouteTarget &&
|
||||
params.route.sessionKey === params.route.mainSessionKey &&
|
||||
inboundLastRouteSessionKey === params.route.mainSessionKey &&
|
||||
shouldUpdateMainLastRoute
|
||||
) {
|
||||
updateLastRouteInBackground({
|
||||
@@ -357,7 +364,7 @@ export async function processMessage(params: {
|
||||
});
|
||||
} else if (
|
||||
dmRouteTarget &&
|
||||
params.route.sessionKey === params.route.mainSessionKey &&
|
||||
inboundLastRouteSessionKey === params.route.mainSessionKey &&
|
||||
pinnedMainDmRecipient
|
||||
) {
|
||||
logVerbose(
|
||||
|
||||
Reference in New Issue
Block a user