Last active
May 16, 2016 22:54
-
-
Save sprngr/ab71139e2853d14dcfef981f4d8b524c to your computer and use it in GitHub Desktop.
Hubot listener middleware example for gating commands based on bot instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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