Hubot : how to pipeline your commands ?

If you got used to creating new commands in your Hubot server, you will probably remember of this syntax :

robot.hear(/say hello/i, function(res) {/*...*/}
robot.respond(/how are you/i, function(res) {/*...*/}

When you want to combine then into one, the easy way out is to create a spare command like this one :

robot.respond(/hello, how are you/i, function(res) {/*...*/}

Things become more difficult when you need combine a set of different instructions. Theorically, it means that you should create n^k different commands.
I was interested in finding how I could change the commands into a full pipeline with the least possible amount of changes.
And I found an answer (maybe not the best indeed) :

https://gist.github.com/libetl/56763f55cf1d1ac7a01eb6476559eb69
Insert the pipeline object into your code.

And then this is how your existing code is going to change :

instead of this :

robot.hear(/say hello/i, function(res) {/*...*/}
robot.respond(/how are you/i, function(res) {/*...*/}

you will write this :

pipeline.hear(/say hello/i, function(robot, res, resolve) {/*...*/;resolve();}
pipeline.respond(/how are you/i, function(robot, res, resolve) {/*...*/;resolve();}

It is important to call resolve() at the end of the execution so the pipeline knows when to start the next step.

the module.exports should look like this one :
module.exports = pipeline.buildAnswer('(my-commands)')

Here you are, your commands now are all included in your pipeline. Enjoy.