mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 14:00:51 +00:00
WhatsApp: move outbound session routing behind plugin boundary
This commit is contained in:
@@ -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: {
|
||||
|
||||
26
extensions/whatsapp/src/session-route.ts
Normal file
26
extensions/whatsapp/src/session-route.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user