Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot listens to wrong parts of the message #43

Closed
dgollub opened this issue Dec 25, 2015 · 3 comments
Closed

Bot listens to wrong parts of the message #43

dgollub opened this issue Dec 25, 2015 · 3 comments
Labels

Comments

@dgollub
Copy link

dgollub commented Dec 25, 2015

Hi,

I am playing around with this library and it is pretty neat, but I ran into the following issue.

const LISTEN_TO = 'direct_message,direct_mention,mention';

controller.hears(['hello','hi'], LISTEN_TO, (bot, message) => {

    bot.api.reactions.add({
        timestamp: message.ts,
        channel: message.channel,
        name: 'robot_face',
    }, (err, res) =>{
        if (err) {
            bot.log("Failed to add emoji reaction :(", err);
        }
    });

    controller.storage.users.get(message.user, (err, user) => {
        if (user && user.name) {
            bot.reply(message, `Hello ${user.name}!!`);
        } else {
            bot.reply(message, "Hello.");
        }
    });

}); // hello, hi

The bot replies Hello. even if the message to it was something like @bot: while I do not hate you ... - the hi in while triggers the bot to reply Hello..

I don't think it should be that way. Is there a bugfix for this or a workaround?

Version: I am using "botkit": "latest", in my package.json file, and it installed version 0.0.4.

@thojkooi
Copy link
Contributor

Try ["\s*hi", "\s*hello"]

Hears takes a regex pattern (or patterns). You will want to match the start of a word.

The \s* will match 0 > unlimited whitespace infront of the hi or hello. So it will match against:

hi, how are you?

but not against:

while I do not hate you

@benbrown
Copy link
Contributor

Another useful example:

["^hello"] matches only the start of the string

@dgollub
Copy link
Author

dgollub commented Dec 28, 2015

@benbrown and @Glowbal Oh boy. Thanks for reminding me about the regex feature. When I first read the docs I actually saw that and thought to myself "Nice. That'll be useful." and then promptly and completely forgot about when I went on implementing my little toy bot. Derp.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants