@@ -12,7 +12,6 @@ import {
1212 resolveWhatsAppAccount ,
1313 type ResolvedWhatsAppAccount ,
1414} from "./accounts.js" ;
15- import { handleWhatsAppAction } from "./action-runtime.js" ;
1615import { createWhatsAppLoginTool } from "./agent-tools-login.js" ;
1716import { whatsappApprovalAuth } from "./approval-auth.js" ;
1817import type { WebChannelStatus } from "./auto-reply/types.js" ;
@@ -43,7 +42,6 @@ import {
4342 normalizeWhatsAppTarget ,
4443} from "./runtime-api.js" ;
4544import { getWhatsAppRuntime } from "./runtime.js" ;
46- import { sendMessageWhatsApp , sendPollWhatsApp } from "./send.js" ;
4745import { resolveWhatsAppOutboundSessionRoute } from "./session-route.js" ;
4846import { whatsappSetupAdapter } from "./setup-core.js" ;
4947import {
@@ -54,6 +52,22 @@ import {
5452} from "./shared.js" ;
5553import { collectWhatsAppStatusIssues } from "./status-issues.js" ;
5654
55+ type WhatsAppSendModule = typeof import ( "./send.js" ) ;
56+ type WhatsAppActionRuntimeModule = typeof import ( "./action-runtime.js" ) ;
57+
58+ let whatsAppSendModulePromise : Promise < WhatsAppSendModule > | undefined ;
59+ let whatsAppActionRuntimeModulePromise : Promise < WhatsAppActionRuntimeModule > | undefined ;
60+
61+ async function loadWhatsAppSendModule ( ) {
62+ whatsAppSendModulePromise ??= import ( "./send.js" ) ;
63+ return await whatsAppSendModulePromise ;
64+ }
65+
66+ async function loadWhatsAppActionRuntimeModule ( ) {
67+ whatsAppActionRuntimeModulePromise ??= import ( "./action-runtime.js" ) ;
68+ return await whatsAppActionRuntimeModulePromise ;
69+ }
70+
5771function normalizeWhatsAppPayloadText ( text : string | undefined ) : string {
5872 return ( text ?? "" ) . replace ( / ^ (?: [ \t ] * \r ? \n ) + / , "" ) ;
5973}
@@ -125,8 +139,10 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> =
125139 outbound : {
126140 ...createWhatsAppOutboundBase ( {
127141 chunker : chunkText ,
128- sendMessageWhatsApp,
129- sendPollWhatsApp,
142+ sendMessageWhatsApp : async ( ...args ) =>
143+ await ( await loadWhatsAppSendModule ( ) ) . sendMessageWhatsApp ( ...args ) ,
144+ sendPollWhatsApp : async ( ...args ) =>
145+ await ( await loadWhatsAppSendModule ( ) ) . sendPollWhatsApp ( ...args ) ,
130146 shouldLogVerbose : ( ) => getWhatsAppRuntime ( ) . logging . shouldLogVerbose ( ) ,
131147 resolveTarget : ( { to, allowFrom, mode } ) =>
132148 resolveWhatsAppOutboundTarget ( { to, allowFrom, mode } ) ,
@@ -260,7 +276,9 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> =
260276 const messageId = String ( messageIdRaw ) ;
261277 const emoji = readStringParam ( params , "emoji" , { allowEmpty : true } ) ;
262278 const remove = typeof params . remove === "boolean" ? params . remove : undefined ;
263- return await handleWhatsAppAction (
279+ return await (
280+ await loadWhatsAppActionRuntimeModule ( )
281+ ) . handleWhatsAppAction (
264282 {
265283 action : "react" ,
266284 chatJid :
0 commit comments