Randomized message output
# 📖tutorials
w
Hi guys🙂 First, thanks to @jolly-policeman-82775 for inspiring me to post this, as his mini-tutorials are helping a lot of people on the server. Second, I'm posting this as I got asked this question twice in the past week, so I thought this might be useful for some bot builders. It's a simple code that prompts the bot to each time to ask different questions. The goal is to prevent the chatbot from always asking the same question and to improve user experience (this is especially useful for workflows with loop questions). I like this method, as before I tried to do it with an AI task and conversation summary, but the problem was that the first message would always have to be repeated. Please see the example in the photo for more clarity! It's a simple process: 1) Insert an execute code card on your node 2) Paste the following code in your execute code card: // Input what messages you would like to randomly appear const messages = ["Greetings my friend, how can I help you today!", "Hello hello, what's up?", "Long times no see, what's new?"]; // Select a random index for the possible messages const randomIndex = Math.floor(Math.random() * messages.length); // Choose in which variable to store the randomazied message workflow.welcomeMSG = messages[randomIndex]; 3) Underneath your execute code, insert a text message card and write '@[your variable's name]' In my example, I used a variation of welcome messages, but you can choose whatever you prefer. Also, don't forget to change or create a variable name so it matches the one at the bottom of your pasted code. Again, it's a simple tutorial and not as complex as @quick-musician-29561's usual gems, but I believe this might help a few people! Happy Bot Building
j
ummm
1 sec man
is it not like this ?
w
Oh I didn’t see that one😂😂😂 @jolly-policeman-82775
You are on it Theo! I will remove this one then👍
j
Lol no worries keep this one open
Ooks better
Looks
w
I could have saved a bit of time if I knew, would have sent people there🥲
j
Lol
q
@wide-oyster-38514 @jolly-policeman-82775 There are never too many good Botpress tutorials! 🛠️ 💎
c
2 is better than one haha 😉 thanks @wide-oyster-38514
t
Hi Theo, I hope you are well. So what is it instead, would you have the correct screenshot?
j
both works fine man