hubotio / hubot

A customizable life embetterment robot.
https://hubotio.github.io/hubot/
MIT License
16.64k stars 3.75k forks source link

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

Closed KeesCBakker closed 1 year ago

KeesCBakker commented 1 year ago

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);
    });
joeyguerra commented 1 year ago

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.

KeesCBakker commented 1 year ago

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

image

KeesCBakker commented 1 year ago

Fortunately the upgrade was not very hard: https://github.com/KeesCBakker/hubot-command-mapper/commit/2504fd5fa1fbe5c27b04044e0fdceb1a514e8e51

joeyguerra commented 1 year ago

@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?

KeesCBakker commented 1 year ago

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

joeyguerra commented 1 year ago

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