In my cloud botpress, I am calling an api, from wh...
# 🌎general
w
In my cloud botpress, I am calling an api, from which I am getting an array of objects, each object contains information of a user, now I want to loop though each item in result array, and send messages containing object in a formate, how can I do it?
a
Hey @worried-plumber-65401, loops are tricky. Give me a minute and I'll post a handy guide for ya
w
okay
@acceptable-kangaroo-64719 Have you got anything?
a
sorry, got pulled into a meeting. The gist of it is you need two nodes: one to do your thing, another to increment and set
event.state._stacktrace = []
gimmie about 20 minutes and I'll grab some screenshots
w
yeah sure.
a
thanks for your patience, here's some visuals to help out. In my example, I'm getting an array of cat pictures from cats-as-a-service API, and then getting GPT to come up with a name and description for each cat. This is my main flow
Then the actual loop happens here
In the first node, I go through the
items
object and take the bits I need for the image. Then I feed them to the AI task.
This is basically a
for
loop, and I create a counter called
i
that is equal to the length of the array
After my AI task, I increment
i
and, if it is less than
items.length
I go to the
loop
node where I reset the stacktace to avoide infinite loop detection.
You can load up the bot in your own cloud wiht this file
w
Thanks alot, It will solve my problem.
@acceptable-kangaroo-64719 just one question how could I load the above file in my cloud, I am not able to see any such option in botpress cloud website.
a
click on the logo in the top left corner
w
yups thanks again.