diff --git a/extensions/whatsapp/src/auto-reply/monitor/process-message.ts b/extensions/whatsapp/src/auto-reply/monitor/process-message.ts index e83a9ffd8cc..798aece49ab 100644 --- a/extensions/whatsapp/src/auto-reply/monitor/process-message.ts +++ b/extensions/whatsapp/src/auto-reply/monitor/process-message.ts @@ -93,7 +93,7 @@ function readWhatsAppMessageReceivedHookOptIn(value: unknown): boolean | undefin if (pluginHooks?.messageReceived === undefined) { return undefined; } - return pluginHooks?.messageReceived === true; + return pluginHooks.messageReceived; } function shouldEmitWhatsAppMessageReceivedHooks(params: { @@ -108,19 +108,11 @@ function shouldEmitWhatsAppMessageReceivedHooks(params: { ? channelConfig.accounts[params.accountId] : undefined; - // Try channel/account config first (documented path) - const channelOptIn = + return ( readWhatsAppMessageReceivedHookOptIn(accountConfig) ?? - readWhatsAppMessageReceivedHookOptIn(channelConfig); - if (channelOptIn !== undefined) { - return channelOptIn; - } - - // Fallback to plugin config path for compatibility - const pluginConfig = params.cfg.plugins?.entries?.whatsapp?.config as - | WhatsAppMessageReceivedHookConfig - | undefined; - return readWhatsAppMessageReceivedHookOptIn(pluginConfig) ?? false; + readWhatsAppMessageReceivedHookOptIn(channelConfig) ?? + false + ); } function emitWhatsAppMessageReceivedHooks(params: { diff --git a/src/config/zod-schema.providers-whatsapp.ts b/src/config/zod-schema.providers-whatsapp.ts index 22755439c0c..b150d5b119a 100644 --- a/src/config/zod-schema.providers-whatsapp.ts +++ b/src/config/zod-schema.providers-whatsapp.ts @@ -48,6 +48,13 @@ const WhatsAppAckReactionSchema = z .strict() .optional(); +const WhatsAppPluginHooksSchema = z + .object({ + messageReceived: z.boolean().optional(), + }) + .strict() + .optional(); + function stripDeprecatedWhatsAppNoopKeys(value: unknown): unknown { if (!value || typeof value !== "object" || Array.isArray(value)) { return value; @@ -97,6 +104,7 @@ function buildWhatsAppCommonShape(params: { useDefaults: boolean }) { replyToMode: ReplyToModeSchema.optional(), heartbeat: ChannelHeartbeatVisibilitySchema, healthMonitor: ChannelHealthMonitorSchema, + pluginHooks: WhatsAppPluginHooksSchema, }; } @@ -150,12 +158,6 @@ const WhatsAppAccountObjectSchema = z /** Override auth directory for this WhatsApp account (Baileys multi-file auth state). */ authDir: z.string().optional(), mediaMaxMb: z.number().int().positive().optional(), - pluginHooks: z - .object({ - messageReceived: z.boolean().optional(), - }) - .strict() - .optional(), }) .strict(); @@ -178,12 +180,6 @@ const WhatsAppConfigObjectSchema = z }) .strict() .optional(), - pluginHooks: z - .object({ - messageReceived: z.boolean().optional(), - }) - .strict() - .optional(), }) .strict() .superRefine((value, ctx) => {