Yes, you can achieve this in Botpress by using a combination of content elements and custom code actions. Here’s a step-by-step guide to create a bot that randomly picks one of 10 different greeting messages to respond to users:Create Greeting Messages:Store your greeting messages in a JSON array. You can define this array within a custom action or in a configuration file.Custom Action:Create a custom action that selects a random greeting from the array.Integrate Custom Action into a Bot Flow:Use the custom action in your bot's flow to set the selected greeting message as a variable.Use the variable in a bot response to send the greeting to the user.Here are the detailed steps:
Step 1: Define Greeting MessagesCreate a JSON array with your greetings.{
"greetings": [
"Hello! How can I assist you today?",
"Hi there! What can I do for you?",
"Hey! Need any help?",
"Good day! How can I help?",
"Hello! What can I do for you?",
"Hi! How can I assist?",
"Greetings! How can I help you today?",
"Hey there! What do you need assistance with?",
"Hi! How may I help you?",
"Hello! What can I assist you with?"
]
}
Step 2: Create a Custom ActionCreate a custom action in Botpress to pick a random greeting. You can create this action in data/actions.const greetings = [
"Hello! How can I assist you today?",
"Hi there! What can I do for you?",
"Hey! Need any help?",
"Good day! How can I help?",
"Hello! What can I do for you?",
"Hi! How can I assist?",
"Greetings! How can I help you today?",
"Hey there! What do you need assistance with?",
"Hi! How may I help you?",
"Hello! What can I assist you with?"
];
function getRandomGreeting() {
const randomIndex = Math.floor(Math.random() * greetings.length);
return greetings[randomIndex];
}
const selectedGreeting = getRandomGreeting();
bp.dialog.setVariable('greetingMessage', selectedGreeting);