Skip to content

Instantly share code, notes, and snippets.

@sprngr
Last active May 16, 2016 22:54
Show Gist options
  • Save sprngr/ab71139e2853d14dcfef981f4d8b524c to your computer and use it in GitHub Desktop.
Save sprngr/ab71139e2853d14dcfef981f4d8b524c to your computer and use it in GitHub Desktop.
Hubot listener middleware example for gating commands based on bot instance
// Setup Listener Middleware
robot.listenerMiddleware(function(context, next, done){
var mode = context.listener.options.mode || '';
if (mode === '' || process.env.BOT_MODE === mode) {
next(done);
} else {
done();
}
});
// Register listeners
robot.respond(/test command0/i, function(msg) {
// Will work in any instance
}
robot.respond(/test command1/i, {mode: 'instance1'}, function(msg) {
// Will only work in instance1
}
robot.respond(/test command2/i, {mode: 'instance2'}, function(msg) {
// Will only work in instance2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment