admin管理员组

文章数量:1357633

I wrote code in Validation (Advanced Configuration) to validate a Capture Information - Single Choice type. When I clicked on one of the choices I set up before and called the validate function, I got the error:

Error executing validation "inline-vld-8ba292d8e1.js" [Error, Cannot read properties of undefined (reading 'trim')]

In my opinion, Botpress called the validation function before the input received a value, leading to this error.

Validation Code (JavaScript):

function validate(input: { value: string }): boolean {
    const normalizedInput = input.value.trim().toLowerCase();
    return ["buy", "rent", "offplan"].includes(normalizedInput);
}

Logs (7 items - 1 error):

[Capture] User clicked on a button, so we are skipping the cognitive extraction  
Executing capture card custom validation  
Error executing validation "inline-vld-8ba292d8e1.js"  
[Capture] Field validation failed. Extracted: "Buy". Input: Buy  
[Capture] Extraction failed (2/2 attempts)  
[Capture] Prompt failed. Maximum number of retries reached.  
[Capture] Prompt failed  

Screenshots:

  • Validation Code & Capture Information Card
  • Event Debugger
  • Logs

What I Tried

I modified the code as follows, but the issue persists:

const normalizedInput = input?.value?.trim().toLowerCase() || "";

If I use an Execute Code Card after the Capture Information Card, the value is already stored in a variable, and this issue does not occur. However, if the value is invalid, the user is forced to enter the information from the beginning.

Alternatively, using an Expression Card after each Capture Information Card allows validation without an undefined error, but an invalid value still forces the user to re-enter the information from the start of the node.

Related Screenshot:

  • Expression Card

Does anyone have a solution to prevent Botpress from triggering the validation function before the input receives a value?

本文标签: