hubotio / hubot

A customizable life embetterment robot.

Home Page:https://hubotio.github.io/hubot/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upgrade from 7 to 9 causes: "Incorrect number of arguments for middleware callback (expected 1, got 3)"

KeesCBakker opened this issue · comments

The code I'm using from the bot is:

 robot.receiveMiddleware((context, next, done) => {
        var text = context.response.message.text;
        var newText = mapping.process(text);
        if (text != newText) {
            context.response.message.text = newText;
            if (robot.logger) {
                robot.logger.info(`Routing '${text}' to '${newText}'.`);
            }
        }
        next(done);
    });

Yes, there was an API change between 7 and v9. Specifically, the move to async/await style code. The code above would look like the following for v9:

 robot.receiveMiddleware(async context => {
        var text = context.response.message.text;
        var newText = mapping.process(text);
        if (text != newText) {
            context.response.message.text = newText;
            if (robot.logger) {
                robot.logger.info(`Routing '${text}' to '${newText}'.`);
            }
        }
        return true;
    });

Returning true will tell the code to continue the pipeline. Returning false will halt the pipeline. Looking at robot.receive, you'll see the infrastructure that does this.

Please let me know how you move forward. I haven't seen much feedback after resuscitating Hubot's development and am super curious to hear, collaborate and see the community that's still using Hubot.

Awesome! Let me upgrade some code. Looks like we also need to update hubot-mock-adapter.

image

Fortunately the upgrade was not very hard: KeesCBakker/hubot-command-mapper@2504fd5

@KeesCBakker I'm really glad to hear that. I've been making some big moves in the codebase with very little feedback to guide decisions.

What are your thoughts about closing this issue?

Yeah, we can close it. Should I open a new ticket for the mock adapter peer dependency?

@KeesCBakker yes please. That way it stands out as I continue to monitor issues from the main repo page.