diff --git a/api/src/chat/schemas/types/message.ts b/api/src/chat/schemas/types/message.ts index 451d7db4..aceb4e18 100644 --- a/api/src/chat/schemas/types/message.ts +++ b/api/src/chat/schemas/types/message.ts @@ -312,11 +312,6 @@ export const validMessageTextSchema = z.object({ message: z.string(), }); -// is-message validation -const MESSAGE_REGEX = /^function \(context\) \{[^]+\}/; - -export const messageRegexSchema = z.string().regex(MESSAGE_REGEX); - export const textSchema = z.array(z.string().max(1000)); const quickReplySchema = z @@ -391,6 +386,7 @@ const attachmentBlockMessageSchema = z.object({ // BlockMessage Schema export const blockMessageObjectSchema = z.union([ + textSchema, pluginBlockMessageSchema, textBlockMessageSchema, buttonMessageSchema, diff --git a/api/src/chat/validation-rules/is-message.ts b/api/src/chat/validation-rules/is-message.ts index 20fc2f2b..dcf27a9d 100644 --- a/api/src/chat/validation-rules/is-message.ts +++ b/api/src/chat/validation-rules/is-message.ts @@ -16,36 +16,11 @@ import { import { BlockMessage, blockMessageObjectSchema, - messageRegexSchema, - textSchema, } from '../schemas/types/message'; -/* eslint-disable no-console */ export function isValidMessage(msg: any) { - if (typeof msg === 'string' && msg !== '') { - const result = messageRegexSchema.safeParse(msg); - if (!result.success) { - console.error('Block Model: Invalid custom code.', result.error); - return false; - } - return true; - } else if (Array.isArray(msg)) { - const result = textSchema.safeParse(msg); - if (!result.success) { - console.error('Block Model: Invalid text message array.', result.error); - } - return result.success; - } else if (typeof msg === 'object' && msg !== null) { - const result = blockMessageObjectSchema.safeParse(msg); - if (!result.success) { - console.error('Block Model: Object validation failed!', result.error); - } - return result.success; - } - console.log('Validation reached default false'); - return false; + return blockMessageObjectSchema.safeParse(msg).success; } -/* eslint-enable no-console */ @ValidatorConstraint({ async: false }) export class MessageValidator implements ValidatorConstraintInterface {