fix: narrow whatsapp hook config

This commit is contained in:
Marcus Castro
2026-05-27 21:58:18 -03:00
parent a951803f7b
commit 27003a8d5a
2 changed files with 13 additions and 25 deletions

View File

@@ -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: {

View File

@@ -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) => {