Troubleshooting Empty Array Display in Chatbot, bu...
# 🤝help
h
I'm working on adding a feature to a chatbot that displays available slots at a barbershop. Initially, I tried displaying these slots using a single choice element, but that approach was unsuccessful. Now, I'm fetching the slots from an API and storing them in an array called
workflow.slots
. While the results are visible in the console, they don't appear in the chat interface—instead, I just see "Available Slots[]", indicating the array is empty at the time of display. I've attempted to manage the asynchronous nature of the API call with
await
, but I was not successful. Can you help me troubleshoot why the array might be empty in the chat, even though it populates correctly in the console? Attached you can find my console log, my code and an overview of the chatbot flow. https://cdn.discordapp.com/attachments/1236388949119864932/1236388949342289970/Bildschirmfoto_2024-05-04_um_20.44.19.png?ex=6637d470&is=663682f0&hm=cf4f6e5cbef30ec00addad3013cd2196230b0ea89898904c3efed1eedd19866d& https://cdn.discordapp.com/attachments/1236388949119864932/1236388949836955769/image.png?ex=6637d470&is=663682f0&hm=6e424ab4af30120ba75b55f14e49257472559c55dd814cb3200af77bc6d948e0& https://cdn.discordapp.com/attachments/1236388949119864932/1236388950088876144/Chatbotflow.png?ex=6637d470&is=663682f0&hm=9ed22952acc2d8751b1deb26158a9ffe2083caaec300f92873a23aa5b20bf197&
f
Hey there, I take it that the 2nd image is your code that fetches the available slots at the barber shop. You can add await before calling the async function
executeDataFetch
, which you are doing at the bottom of your code. So
await executeDataFetch();
I would probably delete the async function
executeDataFetch
and just have
await fetchData();
at the bottom of my execute code card.
Should work
h
Hi Decay, Thank you very much; it worked! Not all heroes wear capes! 🙂 Now, I need to figure out how to put the array into a single choice card. If you have any tips on that, I would appreciate it.
f
That is amazing to hear! Guilhermy has a great tutorial on that https://discord.com/channels/1108396290624213082/1135960836209393676
b
Decay should wear a cape tbh
f
Thank you Robert!
4 Views