Fernando Carmine
TTypebot
ā¢Created by Fernando Carmine on 4/7/2025 in #help-and-questions
šØ How can I display the results of my script in the Typebot chat?
ā
Step-by-step guide
1. ā
Save the result as a variable in Typebot
In your script block, make sure you're using the Typebot function setVariable() correctly:
llamarAPI()
.then(datos => {
console.log("š API Response:");
console.log(datos);
setVariable('facturas', datos); // save the JSON array to a Typebot variable
return true;
})
.catch(error => {
console.error(error);
setVariable('errorAPI', 'Could not retrieve data.');
return false;
}); I have a script block that successfully calls an external API and stores the result (a JSON array) using setVariable('facturas', datos);. The script works correctly and I can see the data in the console.
Now I want to display the list of results (invoices) in the chat. What's the best way to do this?
Is there a way to loop through the array and show each item?
Can I use a formatted text block or cards to display each invoice?
Should I process the array into a single string inside the script and use a single text variable?
Any examples or best practices would be appreciated!
2 replies
TTypebot
ā¢Created by Fernando Carmine on 4/7/2025 in #help-and-questions
šÆ Question about using variables in Script block
Hi everyone! I'm working with a Script block in Typebot and I need to use some variables previously collected in the flow, like numeroInterno and codigoPago.
I'm trying to access them in the script like this:
console.log("Internal Number:", numeroInterno);
console.log("Payment Code:", codigoPago);
But I get this error:
ReferenceError: Cannot access 'numeroInterno' before initialization
š¤ What's the correct way to access flow variables inside a Script block?
Do I need to declare them or use a specific syntax to make them available as JavaScript variables?
Any help or working example would be greatly appreciated š
3 replies