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