Botkit: How to use a random bot.reply message to welcome users

Created on 26 Nov 2016  路  4Comments  路  Source: howdyai/botkit

Hello,

I couldn't find the actual function or logic that is how can my bot replies a random greetings whenever someone mentions or message the bot. As you see below, my current line is .. bot.reply(message, 'Hi there!')

controller.hears(['hi', 'hello', 'good morning'], ['direct_message','direct_mention','mention'], function (bot, message) {
  bot.reply(message, 'Hi there!')
})

What if I have 4-5 different/random greetings? What function should I use..any example would be good. Thanks

help wanted

Most helpful comment

I'm not sure botkit should have a function here. Maybe use something like this:

var message_options = [
    "Hello there!",
    "How are you?",
    "What's up?"
]
var random_index = Math.floor(Math.random() * message_options.length)
var chosen_message = message_options[random_index]

bot.reply(message, chosen_message) 

All 4 comments

I'm not sure botkit should have a function here. Maybe use something like this:

var message_options = [
    "Hello there!",
    "How are you?",
    "What's up?"
]
var random_index = Math.floor(Math.random() * message_options.length)
var chosen_message = message_options[random_index]

bot.reply(message, chosen_message) 

Thanks @agamrafaeli It worked.

I used the following snippet

controller.hears(['hello','hey','hi','aloha'], ['direct_message','direct_mention','mention'], function(bot, message) {
    var message_options = [
        "Hello there!",
        "Hello.",
        "Yes, I'm listening...",
        "Hi! How can I help?",
        "Hey, what's up!",
        "Yes, tell me! What are you looking for?",
        "What's up?"
    ]
    var random_index = Math.floor(Math.random() * message_options.length)
    var chosen_message = message_options[random_index]

  bot.reply(message, chosen_message)

  });

@peterswimm I think we can close this issue now.

@agamrafaeli Will do!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ansarizafar picture ansarizafar  路  4Comments

HannanShaik picture HannanShaik  路  3Comments

matueranet picture matueranet  路  4Comments

TheJimFactor picture TheJimFactor  路  4Comments

imjul1an picture imjul1an  路  3Comments