Salvation
Salvation6d ago

Please help urgent

I am new to voiceflow and im following a tutorial , i am basing my test off a real cleaning company and im making a feature where the ai can collect information adn send it to a crm for "staff" to confirm a price , however i am getting a problem when testing , even if i dont put in a valid number , the ai continues its questions , ive tried everything to try fix this with fallbacks , conidtions , etc but nothing has worked it wither always falls back or always goes forward not matter what the user actually says , currently i have it back to where the oringal problem laid so i dont get confused , so there is only one lien of script in the javascript codeblock that says bedroom_number = Number(bedroom_number) , and default goes to next question , fail goes to last utterance , again tho ill say this only makes it so whatever the user says it goes forward none the less , urgentr help please anyone
No description
No description
No description
3 Replies
Tico | Voiceflow Assistant
I can help you fix the number validation issue! The problem is that your current setup only converts the input to a number but doesn't actually validate whether it's a valid number before proceeding. The Issue When you use bedroom_number = Number(bedroom_number), JavaScript will convert invalid inputs (like "abc") to NaN (Not a Number), but your condition step doesn't check for this. The flow continues regardless because the conversion always "succeeds" technically. Solution: Proper Number Validation Here's how to fix it using a Code Step followed by a Condition Step: 1. Code Step - Validate the Input
// Assumes bedroom_number variable already exists from user input
bedroom_number = bedroom_number.trim();

// Convert to number
var bedroom_num = Number(bedroom_number);

// Check if it's a valid number and positive
if (isNaN(bedroom_num) || bedroom_num <= 0 || !Number.isInteger(bedroom_num)) {
is_valid_bedroom = false;
} else {
is_valid_bedroom = true;
bedroom_number = bedroom_num;
}
// Assumes bedroom_number variable already exists from user input
bedroom_number = bedroom_number.trim();

// Convert to number
var bedroom_num = Number(bedroom_number);

// Check if it's a valid number and positive
if (isNaN(bedroom_num) || bedroom_num <= 0 || !Number.isInteger(bedroom_num)) {
is_valid_bedroom = false;
} else {
is_valid_bedroom = true;
bedroom_number = bedroom_num;
}
Important: Create the is_valid_bedroom variable in Voiceflow before this code step (set it to false initially). 2. Condition Step - Route Based on Validation After the code step, add a Condition Step: - If is_valid_bedroom equals true → Continue to next question - Else → Go back to ask for bedroom number again (fallback) Alternative: Use Capture Step with Rules For a simpler approach, use the Capture Step with built-in validation: 1. Add a Capture Step 2. Create a custom entity for bedroom_number 3. In the Rules field, add: "The bedroom number must be a positive whole number between 1 and 20" 4. Enable Automatically Reprompt so it asks again if validation fails This approach handles validation automatically without needing code! Key Points - Number() converts anything, even invalid inputs (returns NaN)
Tico | Voiceflow Assistant
- Always check with isNaN() to verify it's actually a number - Use Number.isInteger() if you need whole numbers only - Create validation variables before using them in code steps Resources: - JavaScript Step Documentation - Condition Step Documentation - Capture Step with Validation Try the code validation approach above, and let me know if you need help implementing it!
Voiceflow
JavaScript step
Run custom JavaScript to manipulate variables or control logic.
Voiceflow
Condition step
Creating Conditional Paths In conversational AI design, controlling the flow and logic of interactions is crucial for delivering effective user experiences. Conditions allow you to add flexibility and dynamic decision-making to your conversation flows using "if-then" logic, allowing you to branch th…
Voiceflow
Capture step
❗️This feature is part of the old way to build using Voiceflow.Although this feature remains available, we recommend using the Agent step and Tool step to build modern AI agents. Legacy features, such as the Capture step and Intents often consume more credits and lead to a worse user experience. Int…
Salvation
SalvationOP6d ago
where do i create the is_valid_bedroom variable?

Did you find this page helpful?