WhatsApp: move outbound session routing behind plugin boundary

This commit is contained in:
Gustavo Madeira Santana
2026-03-18 04:03:14 +00:00
parent 6ba15aadcc
commit fa896704d2
2 changed files with 28 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "openclaw/plugin-sdk
import { resolveWhatsAppAccount, type ResolvedWhatsAppAccount } from "./accounts.js";
import { looksLikeWhatsAppTargetId, normalizeWhatsAppMessagingTarget } from "./normalize.js";
import { getWhatsAppRuntime } from "./runtime.js";
import { resolveWhatsAppOutboundSessionRoute } from "./session-route.js";
import { whatsappSetupAdapter } from "./setup-core.js";
import {
createWhatsAppPluginBase,
@@ -82,6 +83,7 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
},
messaging: {
normalizeTarget: normalizeWhatsAppMessagingTarget,
resolveOutboundSessionRoute: (params) => resolveWhatsAppOutboundSessionRoute(params),
parseExplicitTarget: ({ raw }) => parseWhatsAppExplicitTarget(raw),
inferTargetChatType: ({ to }) => parseWhatsAppExplicitTarget(to)?.chatType,
targetResolver: {

View File

@@ -0,0 +1,26 @@
import {
buildChannelOutboundSessionRoute,
type ChannelOutboundSessionRouteParams,
} from "openclaw/plugin-sdk/core";
import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "openclaw/plugin-sdk/whatsapp";
export function resolveWhatsAppOutboundSessionRoute(params: ChannelOutboundSessionRouteParams) {
const normalized = normalizeWhatsAppTarget(params.target);
if (!normalized) {
return null;
}
const isGroup = isWhatsAppGroupJid(normalized);
return buildChannelOutboundSessionRoute({
cfg: params.cfg,
agentId: params.agentId,
channel: "whatsapp",
accountId: params.accountId,
peer: {
kind: isGroup ? "group" : "direct",
id: normalized,
},
chatType: isGroup ? "group" : "direct",
from: normalized,
to: normalized,
});
}