Files
openclaw/extensions/whatsapp/src/outbound-adapter.ts
Rubén Cuevas 652f34103a fix(whatsapp): sanitize tool XML and hide configured error text (#71830)
Merged via squash.

Prepared head SHA: 184d4a25e4
Co-authored-by: rubencu <4742789+rubencu@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
2026-04-29 01:43:25 -03:00

37 lines
1.4 KiB
TypeScript

import { type ChannelOutboundAdapter } from "openclaw/plugin-sdk/channel-send-result";
import { chunkText } from "openclaw/plugin-sdk/reply-chunking";
import { shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
import { createWhatsAppOutboundBase } from "./outbound-base.js";
import { normalizeWhatsAppPayloadText } from "./outbound-media-contract.js";
import { resolveWhatsAppOutboundTarget } from "./resolve-outbound-target.js";
type WhatsAppSendModule = typeof import("./send.js");
let whatsAppSendModulePromise: Promise<WhatsAppSendModule> | undefined;
function loadWhatsAppSendModule(): Promise<WhatsAppSendModule> {
whatsAppSendModulePromise ??= import("./send.js");
return whatsAppSendModulePromise;
}
function normalizeOutboundText(text: string | undefined): string {
return normalizeWhatsAppPayloadText(text);
}
export const whatsappOutbound: ChannelOutboundAdapter = createWhatsAppOutboundBase({
chunker: chunkText,
sendMessageWhatsApp: async (to, text, options) =>
await (
await loadWhatsAppSendModule()
).sendMessageWhatsApp(to, normalizeOutboundText(text), {
...options,
}),
sendPollWhatsApp: async (to, poll, options) =>
await (await loadWhatsAppSendModule()).sendPollWhatsApp(to, poll, options),
shouldLogVerbose: () => shouldLogVerbose(),
resolveTarget: ({ to, allowFrom, mode }) =>
resolveWhatsAppOutboundTarget({ to, allowFrom, mode }),
normalizeText: normalizeOutboundText,
skipEmptyText: true,
});