🗨 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!
1 Reply
Maybe this can help: https://docs.typebot.io/guides/how-to-create-loops#how-to-create-loops
Typebot Docs
How to create loops? - Typebot Docs