https://discord.gg/botpress logo
Random Answer
# 🤝help
f
Hello people, a few questions from my side (new to Botpress): - Is there any recomendation to get into this? Tutorials all seem old and outdated - I got my very simple Bot working: Autonomous Node with a transition if user response with keyword. Then using a standard node to respond back with an image - working but I would like to respond with random images - there are some complicated workflows with JS, but there should be simple solution Thx, Volker
p
Hi Volker, The videos made within the last year are still pretty accurate, they might not address the issues you are facing tho. If that's the case, I host office hours everyday from 10:30 to 11 am EST for live feedback, demonstrations and answers to your questions. You will have to use an execute code card to achieve the randomization of the images returned. You can place the image links in a table. Use the execute code card to pick a number at random between 0 and the last row of your table and then fetch that via a get record card. You can then pass that to the image card. This is the simplest way I can think of to achieve your goal. Happy Bot Building!
f
Hi Leanne, I was struggeling with this aproach before. Why should I upload the images and store the links in a table when there is a card where I can store the image directly in Botpress. Isn't three a simple example file or tutorial? Should be common question...Thx
p
What card are you referring to when you say "there is a card where I can store the image directly in Botpress."?
f
With „Message Image“ I can respond with a single image, was hoping there would be a similar solution for multiple
Guess there is not a simple solution. Getting into tables and variables together with execute code seems to be the answer, got to dig into that somehow
p
Yeah unfortunately because you want to display random images, if i understood correctly, you can't use the image card that takes in one predefined image as a file. You can only use it with a variable which needs to be assigned previously in some way. Happy to answer any following questions!
f
Crazy, made it work. Thx Leanne
p
That's awesome!
f
Hmm, still got some problems here. I allways got an error becuase the table doesn't start at 0. Also I wanted to get a random image back but no repeating. My idea was to have an extra row in the URL table with unique IDs (memeIDs / type=str) to tackle the 0 problem. Then I used "execute code" to set up these IDs and shuffle them. Another "execute code" for stepping trough and a counter if to reset. Seems to work until here, tested it by printing out the IDs as a message. Main Problem seems to be the get record card with the unique ID. Connecting the str ID to the URL in the table.
Execute operation getRecord("3a2d903e-e2f2-4b9d-9425-ddd444444444") failed: Pt: request/query/id must be integer
Made it work by putting all the URLs direct into a code card
One last question: why should I use a table and not store the URLs directly in a "execute code" node?
Copy code
// List of memes (hardcoded)
const memes = [
  "https://i.imgur.com/Rzknrc0.jpeg",
  "https://i.imgur.com/vg24iBE.jpeg",
  "https://i.imgur.com/pI7tLI5.jpeg",
  "https://i.imgur.com/NJwniVb.jpeg",
  "https://i.imgur.com/EXD1yX5.jpeg",
  "https://i.imgur.com/gMxGW1U.jpeg",
  "https://i.imgur.com/RnYatJc.jpeg",
  "https://i.imgur.com/vo49RVq.jpeg",
  "https://i.imgur.com/pNI1MAi.jpeg",
  "https://i.imgur.com/8JXUZVm.jpeg",
  "https://i.imgur.com/4oDuR11.jpeg",
  "https://i.imgur.com/3F4C46D.jpeg"

];


const randomIndex = Math.floor(Math.random() * memes.length);
workflow.currentMemeUrl = memes[randomIndex];
wouldn't this be the simplest solution?
p
Yeah you can absolutely do that as well, but in terms of extensibility and simplicity, tables are pretty good for that. If you don't foresee the need for your bot to be easy to understand by someone else, than your solution is great!
f
Thx, this is just a fun project. Somehow the bot work within the emulator not bad, but when published it only takes one link. Repeating the same Link
p
Do you mean that it only outputs one of the many links?
f
yeah
p
I'll try it out, and get back to you.
Works for me...
f
On my side it works for a while in the Emulator but published only 2-3 different links.
It's like Botpress is lazy and is repeating.
Had a second aproach where I used a transition from the autonomous node to a standard node. There I used a code card to dispatch a string (meme1, meme2, etc) Then used a transition node in expression mode to output to standard nodes with a single image card. Dispatching seems to work, but not the transition. https://cdn.discordapp.com/attachments/1371844934566412319/1372251159942926337/Screenshot_bot_03.jpg?ex=682617fb&is=6824c67b&hm=c0f47307cee6a1b225c9fefc281ee39335920f965a41c2b379cc1d98e548e8ee&
Copy code
const memeRoutes = [
  "meme1",
  "meme2",
  "meme3",
  "meme4",
  "meme5",
  "meme6",
  "meme7"
];

const randomIndex = Math.floor(Math.random() * memeRoutes.length);
workflow.selectedMemeRoute = memeRoutes[randomIndex];
`
sry for all this noob stuff here
idk feels all a little buggy and unpredictable! Knowing I'm no pro
Okay, I think I found the problem. The Autonomous Node / AI took over. I installed a few check messages like which index, the URL and just a check message at the end of the cards stack. First Screenshot shows all fine, all check messages are there. Second screenshot is repeating the image and not showing the check messages. Also the flow chart shows that it didn't take the transition from the Autonomous Node to the standard https://cdn.discordapp.com/attachments/1371844934566412319/1372272884424114236/Screenshot_bot_05.jpg?ex=68262c37&is=6824dab7&hm=28853499c132e26950591ab527581d46189d89c701c10e59e6dfdfa890be0a0a& https://cdn.discordapp.com/attachments/1371844934566412319/1372272884738822145/Screenshot_bot_06.jpg?ex=68262c37&is=6824dab7&hm=dd21380c2ff0e7ba8d6aa2e2e4bff964d3f21dcf79ca2b0aeea5110b025f1da4&
p
Glad you found your issue!
f
Yeah , but unfortunately not the solution. Any idea how to tackle this?
p
You could try using standard nodes and giving the user choices. The autonomous node can behave in an unpredictable manner and is hard to debug. So if your bot behaves in a sequential manner it would be easier to ensure it works properly.
f
Already worked on this approach, but then I miss the personality and wider range of possible answers. Strange that the transition conditions are not first choice, any recommendations how to write them for an anonymous node? Already wrote this into the instructions
This is my transition card from the autonomous node to the standard. The keyword is "send nudes". Don't wonder is a learning fun project to get into this https://cdn.discordapp.com/attachments/1371844934566412319/1372279245698629692/image.png?ex=68263223&is=6824e0a3&hm=28af1de066795f45d83b6dd76063c368f3e143e3e8632eabbaad32d6b6d10752&
p
The transition condition seems alright, so I think your prompt to the AN could probably be optimized to transition better. I would recommend asking chat to do that.
f
Thanks, will try this
Just wrote into the instructions don't respond to that keyword, working like a charme since then
made me crazy that problem, was convinced Botpress was buggy like hell, didn't thaught about the AI taking over
5 Views