howdyai / botkit-middleware-witai

Middleware for using Wit.ai with Botkit-powered bots
MIT License
87 stars 49 forks source link

Allow messages with only attachments to pass through #13

Closed RobinJayaswal closed 7 years ago

RobinJayaswal commented 7 years ago

Currently when a message with only an attachment is received (for example, a Facebook location message), the message gets caught up in this middleware and never reaches the controller.

This is because in the following code for receiving, there is a check to see if it has text, and if it does not then next() is never called:

middleware.receive = function(bot, message, next) {
        if (message.text) {
            console.log('message has text')
            wit.captureTextIntent(config.token, message.text, function(err, res) {
                if (err) {
                    next(err);
                } else {
                    console.log(JSON.stringify(res));
                    message.intents = res.outcomes;
                    next();
                }
            });
        }
       // we should have something hear to pass through other types of messages even if they don't    have text
    };

I have added a simple else if check that will also pass through other messages, setting an empty array for its intents, and calling next()

anonrig commented 7 years ago

Can you solve the conflicts please? @RobinJayaswal

RobinJayaswal commented 7 years ago

@anonrig Looks like another request you pulled in right before mine had also attempted to address the problem. I've kept his change, but I find that assigning message.intents to be [] rather than simply undefined is the more sensible option, as when you apply this middleware there is an understanding that intents will be appended. The current option doesn't have any advantages from what I can see and leads to more potential for errors.