mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 20:45:16 +00:00
fix: narrow whatsapp hook config
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user