fix: apply feedback

This commit is contained in:
abdou6666 2025-02-04 16:13:14 +01:00
parent abb90fcd12
commit ccd8d95f8f

View File

@ -348,27 +348,43 @@ const quickReplySchema = z
} }
}); });
// pluginBlockMessageObjectSchema in case of plugin
export const pluginBlockMessageObjectSchema = z
.record(z.any())
.superRefine((data, ctx) => {
if (!('plugin' in data)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The object must contain the 'plugin' attribute",
path: ['plugin'],
});
}
});
// BlockMessage Schema // BlockMessage Schema
export const blockMessageObjectSchema = z.object({ export const blockMessageObjectSchema = z.union([
text: z.string().max(1000).optional(), pluginBlockMessageObjectSchema,
attachment: z z.object({
.object({ text: z.string().max(1000).optional(),
type: z.nativeEnum(FileType), attachment: z
payload: z .object({
.union([ type: z.nativeEnum(FileType),
z.object({ url: z.string().url() }), payload: z
z.object({ id: z.string().nullable() }), .union([
]) z.object({ url: z.string().url() }),
.optional(), z.object({ id: z.string().nullable() }),
}) ])
.optional(), .optional(),
elements: z.boolean().optional(), })
cards: z .optional(),
.object({ elements: z.boolean().optional(),
default_action: buttonSchema, cards: z
buttons: z.array(buttonSchema).max(3), .object({
}) default_action: buttonSchema,
.optional(), buttons: z.array(buttonSchema).max(3),
buttons: z.array(buttonSchema).max(3).optional(), })
quickReplies: z.array(quickReplySchema).max(11).optional(), .optional(),
}); buttons: z.array(buttonSchema).max(3).optional(),
quickReplies: z.array(quickReplySchema).max(11).optional(),
}),
]);