I have created an automated list that is generated using an API. I would like to pull an item from this list and display it in another bubble. How do I do this ?
In this topic, we are going to show you how you can select, through a button, an item from an automated list to make it appear on a separate text bubble. (Thank you Tushar Parmar for reviewing this post)
In this thread, we used the Asteroids - NeoWs API from NASA (which is available here) to create an automated list with today’s IDs and names of near earth asteroids.
If you want your user to be able to select an item from that automated list, you need to create a button first. In your “List Auto” bubble, scroll down until you find a section called “Buttons” and click on the chevron to add one:
You can for example name it “Select”. Then you need to set up a target bubble. You can create a simple text bubble called for example “Selected data”. This is the target bubble where the content will be displayed. Before navigating to the new bubble you need to click on “+Add” next to “Data manipulations”. This operation is what will allow your bot to hold the selected index of the item:
First you need to create a new data key that you can call “selected_index” and which must be a “Number” (as shown in the picture below). The “=” operator indicates the value that will be assigned to the “selected_index” variable.
Just across “selected_index” you need to click on “select a data” and then choose “index”:
After that, you need to go to the text bubble you created earlier (“Selected data”), press on “Data key” in the text editor and select “selected_index”:
Then press “Data key” one more time and click on the chevron next to “Liste” (or “List” in English, which contain the data you got from the API), type @@@selected_index@@@ in the input box and click on “id : string”. Please note that the “@@@” symbol (starting and ending) will enable the properties to be displayed in the editor for you to select one of these items.
Now, once a user click on a specific item on your automated list thanks to the “Select” button you added, he will see the ID of the asteroid he selected in a different bubble:
In this exemple, I clicked on the first item on the list, but you need to remember that in your data key (“Liste”) everything starts from 0 (hence the 0 you are seeing in the image above, before the colon):