Skip to content

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

@NxP4Code

Description

@NxP4Code

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),
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions