diff --git a/api/src/chat/schemas/types/message.ts b/api/src/chat/schemas/types/message.ts index 67e3dc0b..f7b370dc 100644 --- a/api/src/chat/schemas/types/message.ts +++ b/api/src/chat/schemas/types/message.ts @@ -348,17 +348,17 @@ const quickReplySchema = z } }); -// Attachment Message Schema -export const objectSchema = z.object({ +// BlockMessage Schema +export const blockMessageObjectSchema = z.object({ text: z.string().max(1000).optional(), attachment: z .object({ type: z.nativeEnum(FileType), payload: z - .object({ - url: z.string().url().optional(), - id: z.string().nullable().optional(), - }) + .union([ + z.object({ url: z.string().url() }), + z.object({ id: z.string().nullable() }), + ]) .optional(), }) .optional(), diff --git a/api/src/chat/validation-rules/is-message.ts b/api/src/chat/validation-rules/is-message.ts index 057c71cb..5ab9c705 100644 --- a/api/src/chat/validation-rules/is-message.ts +++ b/api/src/chat/validation-rules/is-message.ts @@ -15,8 +15,8 @@ import { import { BlockMessage, + blockMessageObjectSchema, messageRegexSchema, - objectSchema, textSchema, } from '../schemas/types/message'; @@ -39,7 +39,7 @@ export function isValidMessage(msg: any) { if ('plugin' in msg) { return true; } - const result = objectSchema.safeParse(msg); + const result = blockMessageObjectSchema.safeParse(msg); if (!result.success) { console.error('Block Model: Object validation failed!', result.error); }