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

controller.hears doesn't trigger when use wrapper for receive handler #217

Open
NxP4Code opened this issue Nov 11, 2020 · 3 comments
Open

Comments

@NxP4Code
Copy link

I am trying to filter messages passed to the Watson. I followed the step to use the wrapper function.

    const receiveMiddleware = (bot, message, next) => {
        if (message.text && message.type == 'direct_message') {
            watsonMiddleware.receive(bot, message, next);
        } else {
            next();
        }
    };

    controller.middleware.receive.use(receiveMiddleware);

Receive function gets registered and it gets executed. Problem is that the following hears function doesn't get triggered. I made sure the intent is matching.

    controller.hears(
        async (message) => {
            return message.watsonData && message.watsonData.intents.length > 0 && message.watsonData.intents[0].intent === 'General_Greetings'
        },
        'direct_message',
        async function (bot, message) {
            await bot.reply(message, message.watsonData.output.text.join('\n'));
        }
    );

Above mentioned hears function gets triggered fine with the following receive handler.

   controller.middleware.receive.use(
        watsonMiddleware.receive.bind(watsonMiddleware),
    );

@Naktibalda
Copy link
Contributor

You have an easy workaround of calling next() after await watsonMiddleware.receive(bot, message);.

It is up to you to implement next parameter in receive method and raise a pull request.

@NxP4Code
Copy link
Author

what is puzzling to me is, why does wrapper doesn't work and direct receive middleware registration works. My understanding is in both cases next is not implemented.

@NxP4Code
Copy link
Author

NxP4Code commented Nov 11, 2020

The following does work, I am still confused why does it work when I do direct middleware registration which doesn't call next().


    const receiveMiddleware = async (bot, message, next) => {
        if (message.text && message.type == 'direct_message') {
            await watsonMiddleware.receive(bot, message);
            next();
        } else {
            next();
        }
    };

    controller.middleware.receive.use(receiveMiddleware);

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

No branches or pull requests

2 participants