WhatsApp: move outbound session routing behind plugin boundary
This commit is contained in:
parent
6ba15aadcc
commit
fa896704d2
@ -18,6 +18,7 @@ import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "openclaw/plugin-sdk
|
|||||||
import { resolveWhatsAppAccount, type ResolvedWhatsAppAccount } from "./accounts.js";
|
import { resolveWhatsAppAccount, type ResolvedWhatsAppAccount } from "./accounts.js";
|
||||||
import { looksLikeWhatsAppTargetId, normalizeWhatsAppMessagingTarget } from "./normalize.js";
|
import { looksLikeWhatsAppTargetId, normalizeWhatsAppMessagingTarget } from "./normalize.js";
|
||||||
import { getWhatsAppRuntime } from "./runtime.js";
|
import { getWhatsAppRuntime } from "./runtime.js";
|
||||||
|
import { resolveWhatsAppOutboundSessionRoute } from "./session-route.js";
|
||||||
import { whatsappSetupAdapter } from "./setup-core.js";
|
import { whatsappSetupAdapter } from "./setup-core.js";
|
||||||
import {
|
import {
|
||||||
createWhatsAppPluginBase,
|
createWhatsAppPluginBase,
|
||||||
@ -82,6 +83,7 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
|
|||||||
},
|
},
|
||||||
messaging: {
|
messaging: {
|
||||||
normalizeTarget: normalizeWhatsAppMessagingTarget,
|
normalizeTarget: normalizeWhatsAppMessagingTarget,
|
||||||
|
resolveOutboundSessionRoute: (params) => resolveWhatsAppOutboundSessionRoute(params),
|
||||||
parseExplicitTarget: ({ raw }) => parseWhatsAppExplicitTarget(raw),
|
parseExplicitTarget: ({ raw }) => parseWhatsAppExplicitTarget(raw),
|
||||||
inferTargetChatType: ({ to }) => parseWhatsAppExplicitTarget(to)?.chatType,
|
inferTargetChatType: ({ to }) => parseWhatsAppExplicitTarget(to)?.chatType,
|
||||||
targetResolver: {
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user