mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:00:44 +00:00
refactor: cache repeated lazy imports
This commit is contained in:
@@ -13,6 +13,15 @@ import { shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS } from "./outbound-send-deps.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 trimLeadingWhitespace(text: string | undefined): string {
|
||||
return text?.trimStart() ?? "";
|
||||
}
|
||||
@@ -54,7 +63,7 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
const send =
|
||||
resolveOutboundSendDep<typeof import("./send.js").sendMessageWhatsApp>(deps, "whatsapp", {
|
||||
legacyKeys: WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS,
|
||||
}) ?? (await import("./send.js")).sendMessageWhatsApp;
|
||||
}) ?? (await loadWhatsAppSendModule()).sendMessageWhatsApp;
|
||||
return await send(to, normalizedText, {
|
||||
verbose: false,
|
||||
cfg,
|
||||
@@ -77,7 +86,7 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
const send =
|
||||
resolveOutboundSendDep<typeof import("./send.js").sendMessageWhatsApp>(deps, "whatsapp", {
|
||||
legacyKeys: WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS,
|
||||
}) ?? (await import("./send.js")).sendMessageWhatsApp;
|
||||
}) ?? (await loadWhatsAppSendModule()).sendMessageWhatsApp;
|
||||
return await send(to, normalizedText, {
|
||||
verbose: false,
|
||||
cfg,
|
||||
@@ -90,7 +99,7 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
},
|
||||
sendPoll: async ({ cfg, to, poll, accountId }) =>
|
||||
await (
|
||||
await import("./send.js")
|
||||
await loadWhatsAppSendModule()
|
||||
).sendPollWhatsApp(to, poll, {
|
||||
verbose: shouldLogVerbose(),
|
||||
accountId: accountId ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user