Skip to content

Commit 66f2fe7

Browse files
committed
fix: narrow whatsapp hook config
1 parent 8464de4 commit 66f2fe7

2 files changed

Lines changed: 13 additions & 25 deletions

File tree

extensions/whatsapp/src/auto-reply/monitor/process-message.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function readWhatsAppMessageReceivedHookOptIn(value: unknown): boolean | undefin
9393
if (pluginHooks?.messageReceived === undefined) {
9494
return undefined;
9595
}
96-
return pluginHooks?.messageReceived === true;
96+
return pluginHooks.messageReceived;
9797
}
9898

9999
function shouldEmitWhatsAppMessageReceivedHooks(params: {
@@ -108,19 +108,11 @@ function shouldEmitWhatsAppMessageReceivedHooks(params: {
108108
? channelConfig.accounts[params.accountId]
109109
: undefined;
110110

111-
// Try channel/account config first (documented path)
112-
const channelOptIn =
111+
return (
113112
readWhatsAppMessageReceivedHookOptIn(accountConfig) ??
114-
readWhatsAppMessageReceivedHookOptIn(channelConfig);
115-
if (channelOptIn !== undefined) {
116-
return channelOptIn;
117-
}
118-
119-
// Fallback to plugin config path for compatibility
120-
const pluginConfig = params.cfg.plugins?.entries?.whatsapp?.config as
121-
| WhatsAppMessageReceivedHookConfig
122-
| undefined;
123-
return readWhatsAppMessageReceivedHookOptIn(pluginConfig) ?? false;
113+
readWhatsAppMessageReceivedHookOptIn(channelConfig) ??
114+
false
115+
);
124116
}
125117

126118
function emitWhatsAppMessageReceivedHooks(params: {

src/config/zod-schema.providers-whatsapp.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const WhatsAppAckReactionSchema = z
4848
.strict()
4949
.optional();
5050

51+
const WhatsAppPluginHooksSchema = z
52+
.object({
53+
messageReceived: z.boolean().optional(),
54+
})
55+
.strict()
56+
.optional();
57+
5158
function stripDeprecatedWhatsAppNoopKeys(value: unknown): unknown {
5259
if (!value || typeof value !== "object" || Array.isArray(value)) {
5360
return value;
@@ -97,6 +104,7 @@ function buildWhatsAppCommonShape(params: { useDefaults: boolean }) {
97104
replyToMode: ReplyToModeSchema.optional(),
98105
heartbeat: ChannelHeartbeatVisibilitySchema,
99106
healthMonitor: ChannelHealthMonitorSchema,
107+
pluginHooks: WhatsAppPluginHooksSchema,
100108
};
101109
}
102110

@@ -150,12 +158,6 @@ const WhatsAppAccountObjectSchema = z
150158
/** Override auth directory for this WhatsApp account (Baileys multi-file auth state). */
151159
authDir: z.string().optional(),
152160
mediaMaxMb: z.number().int().positive().optional(),
153-
pluginHooks: z
154-
.object({
155-
messageReceived: z.boolean().optional(),
156-
})
157-
.strict()
158-
.optional(),
159161
})
160162
.strict();
161163

@@ -178,12 +180,6 @@ const WhatsAppConfigObjectSchema = z
178180
})
179181
.strict()
180182
.optional(),
181-
pluginHooks: z
182-
.object({
183-
messageReceived: z.boolean().optional(),
184-
})
185-
.strict()
186-
.optional(),
187183
})
188184
.strict()
189185
.superRefine((value, ctx) => {

0 commit comments

Comments
 (0)