howdyai / botkit-starter-slack

A customizable starting point for building multi-team Slack bots that use the latest APIs
https://botkit.ai
MIT License
176 stars 141 forks source link

Botkit Studio error when the bot is mentioned in a channel with and empty mention #19

Open vicyankoff opened 7 years ago

vicyankoff commented 7 years ago

Hi all,

I successfully installed and ran the bot-start-slack example app. The bot communicates with me fine when I talk to it via direct message. Commands such as hello, thanks, uptime etc work in DM.

I found a case that causes Botkit Studio to crash. Here's how to replicate it.

1) Invite the bot to a channel, for example random. 2) Do an empty mention of the bot, for example "@mybot " and hit enter 3) Botkit Studio will send a message to the channel "I experienced an error with a request to Botkit Studio: undefined"

This error message comes from the catch clause on line 142
.catch(function(err) { bot.reply(message, 'I experienced an error with a request to Botkit Studio: ' + err); debug('Botkit Studio: ', err); });

When you do an empty mention of the bot, the message.text is "" and it causes botkit studio to crash. This only happens on a mention, so If I call controller.studio.runTrigger(bot, "", message.user, message.channel) the error is not triggered.

shishirsharma commented 6 years ago

As a stop gap please use this in .catch({...})

}).catch(function(error) {
    debug('error', error);
    // bot.reply(message, 'I experienced an error with a request to Botkit Studio: ' + error);
    controller.studio.run(bot, 'fallback', message.user, message.channel);
  });